Worksheet - String
Worksheet - String
Hello
3 What will be the output of following code:
s='Hi!'
s1='Hello'
s2=s[:2]+s1[len(s1)-2:]
print(s2)
Hilo
3
4
Welcome
Welcome
Welcome
Welcome
Welcome
9 What will be the output of following program:
str='virat'
for i in str:
print(str.upper())
VIRAT
VIRAT
VIRAT
VIRAT
VIRAT
10 What will be the output of following program:
str='virat'
for i in str:
print(str.upper())
VIRAT
VIRAT
VIRAT
VIRAT
VIRAT
11 What will be the output of following program:
a='hello'
b='virat'
for i in range(len(a)):
print(a[i].upper(),b[i])
Hv
Ei
Lr
La
Ot
12 What will be the output of following program:
print("xyyzxyzxzxyy".count('xyy', 2, 11))
0
13 What will be the output of following program:
print(“hello”+1+2+3)
Error
14 What will be the output of following program:
str1 = "PYTHON2Learn.COM"
print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])
YTH PYTHO ON2Learn.COM PYTHON2Learn.CO PYTHON2Learn.CO
15 What will be the output of following program:
str = "my name is kunfu pandya";
print (str.capitalize())
My name is kunfu pandya
16 What will be the output of following program:
str1 = 'Hello'
str2 ='World!'
print('str1 + str2 = ', str1 + str2)
print('str1 * 3 =', str1 * 3)
3 letters found
18 What will be the output of following program:
s="python2learn"
n= len(s)
m=' '
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):m
= m + s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):m
= m + s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m + '#'
print(m)
npyHho#LEAar
19 What will be the output of following program:
a = "Mahender Singh Dhoni"
a = a.split()
b = a[0][0]+". "+a[1][0]+". "+a[2]
print (b)
M. S. Dhoni
20 What will be the output of following program:
s='Mahender, Singh, Dhoni'
s1=s.split()
for i in s1:
print(i)
Mahender,
Singh,
Dhoni
21 What will be the output of following program:
print("Welcome to Python2learn.com".split())
['Welcome', 'to', 'Python2learn.com']
Hello Python
H
llo Py
lo Python
Hello PythonHello PythonHello Python
Hello PythonString
PYTHON IS E A SY TO LEARN
('PYTHON IS E', 'A', 'SY TO LEARN')
24 What will be the output of following program:
s='mahender, singh, dhoni'
s1=s.split()
for i in s1:
if(i>'n'):
print(i.upper())
else:
print(i)
mahender,
SINGH,
dhoni
#
26 What will be the output of following program:
str="Python2learn.happineSS"
for i in range(len(str)):
if(str[i].isalpha()):
print(str[i-1],end='')
if(str[i].isdigit()):
print(str[i],end='')
SPytho22lear.happineS
27 What will be the output of following program:
str="AB145CVD124N"
for i in range(len(str)):
if(str[i].isalpha()):
print(str[i-1],end='')
if(str[i].isdigit()):
print('#',end='')
NA###5CV###4
28 What will be the output of following program:
str="LOVE 2 LEARN PYTHON"
for i in range(len(str)):
if(str[i].isdigit()):
print(str[i],end='')
if(str[i]=='N'or str[i]=='Y'):
print('#',end='')
2###
29 Write a Program to Count the Number of Vowels in a String.
30 Write a Program to Take in a String and Replace Every Blank Space with Hyphen.
31 Write a Program to Calculate the Length of a String Without Using a Library Function
32 Write a Program to Calculate the Number of Words and the Number of Characters
Present in a String
33 Write a Program to Take in Two Strings and Display the Larger String without Using
Built-in Functions
34 Write a Program to Count Number of Lowercase Characters in a String
37 Write a Program to Form a New String Made of the First 2 and Last 2characters
From a Given String
39 Write a Program to Calculate the Number of Digits and Special characters in a String