0% found this document useful (0 votes)
7 views4 pages

Strings in Python

Uploaded by

bkss238896
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Strings in Python

Uploaded by

bkss238896
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

ADHARSH VIDHYALAYA PUBLIC SCHOOL

Topic : PYTHON REVISION TOUR-2


Sub-Topic : STRING MANIPULATION
Name of Student :
________________________________________

Q1 What will be the output of following code-


str="hello" str[:2]

Ans:

Q2 What will be the output of following code-


str='Hello' res=''
for i in range(len(str)):
res=res+str[i]
print(res)

Ans:

Q3 What will be the output of following code-


s='Hi!'
s1='Hello' s2=s[:2]+s1[len(s1)-2:] print(s2)
Ans:

Q4 What will be the output of following code-


'ba'+'na'*2
Ans:

Q5 What will be the output of following code-


s='Welcome to python4csip.com'
print(s.find('come'))
s.count('o')

Ans:

Q6 What will be the output of following program:


s='Hello'
for i in s:
print(i,end='#')
Ans:

Q7 What will be the output of following program:


for i in 'hardik':
print(i.upper())

Ans:

Q8 What will be the output of following program: s='Hello'


for i in s:
print('Welcome')
Ans:

Q9 What will be the output of following program: str='virat'


for i in str:
print(str.upper())

Ans:

Q10 What will be the output of following program:

a='hello' b='virat'
for i in range(len(a)):
print(a[i],b[i])

Ans:

Q11 What will be the output of following program:


a='hello'
b='virat'
for i in range(len(a)):
print(a[i].upper(),b[i])
Ans:

Q12 What will be the output of following program:


print("xyyzxyzxzxyy".count('xyy', 2, 11))
Ans:

Q13 What will be the output of following program:


print(“hello”+1+2+3)
Ans:

Q14 What will be the output of following program:


str1 = "PUGAL4CS.COM"
print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])
Ans:

Q15 What will be the output of following program:


str = "my name is kunfu pandya";
print (str.capitalize())
Ans:

Q16 What will be the output of following program: str1 = 'Hello'


str2 ='World!'
print('str1 + str2 = ', str1 + str2)
print('str1 * 3 =', str1 * 3)
Ans:

Q17 What will be the output of following program: count = 0


for letter in 'Hello World':
if(letter == 'l'):
count += 1
print(count,'letters found')
Ans:

Q18 What will be the output of following program:


s="python4csip"
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)
Ans:

Q19 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)
Ans:

Q20 What will be the output of following program: s='Mahender, Singh, Dhoni'
s1=s.split()
for i in s1:
print(i)
Ans:

Q21 What will be the output of following program:


"Welcome to Python4csip.com".split()
Ans:

Q22 What will be the output of following program: str ='Hello Python'
print (str) print (str[0])
print (str[2:8])
print (str[3:]) print (str * 3)
print (str + "String")
Ans:

Q23 What will be the output of the program?


line = "PYTHON IS EASY TO LEARN"
L = line.split('a')
for i in L:
print(i, end=' ')
Ans:

Q24 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)
Ans:

Q25 What will be the output of following program:


my_string = 'PUGAL4CS'
for i in range(len(my_string)):
print (my_string)
my_string = '#'
Ans:

Q26 What will be the output of following program:


str="PUGAL4CS.COM"
for i in range(len(str)):
if(str[i].isalpha()):
print(str[i-1],end='')
if(str[i].isdigit()):
print(str[i],end='')

Ans:
Q27 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='')

Ans:

Q28 What will be the output of following program:


str="'PUGAL4CS'"
for i in range(len(str)):
if(str[i].isdigit()):
print(str[i],end='')
if(str[i]=='N'or str[i]=='Y'):
print('#',end='')
Ans:

You might also like