Python String Assignment with Solutions

Python String Assignment with Solutions is based on Python String Data Type. These String Assignments will help you to better understand Python Strings.

Python String Excercise Questions

Q1. Define a string in Python
Q2. is there any different between ‘a’ , “a” and ‘’’a’’’ in python?
Q3. What is a blank string in Python?
Q4. What do you mean by traversing a string?
Q5. What is the index value of first element in any string?
Q6. If the length of any string in 14. What is the positive index value of the last element.
Q7. Which one is the example of string concatenation
a) 6+4
b) ‘4’+’6’
c) ‘a’+’5’+’2’

Q8. Declare a string that contains the following “Programming with Python is lot easier than other Programming Language”
Q9. Declare a string that is spanned in three lines like the given example
Long_string =” Hello rakesh this is going to be a fun
And I love it
What about you “
Q10. Find out the output of the following statement based on the below declaration of a string
string =”PythonProgramInCBSE”
a) print(string[5])
b) print(string[-15])
c) print(string[100])
d) print(string[-4])

Q11. Find out the output of the following statement based on the below declaration of a string
variable =”Hello Python Developers”
a) print(variable[0:10])
b) print(variable[:15])
c) print(variable[3:10:2]
d) print(variable[::]
e) print(variable[::2]
f) print(variable[-1::-1]

Q12. Write the output of the following
String1 =”Python programming is fun”
String2=” This is not \n fun”
Print(string1)
Print(string2)
Q13. find out the output of the following statements
name1 =”Rakesh” name2 =”Arjun”
a) print(name1>name2)
b) print(name1<name2) c) print(name1==name2) d) print(name1!=name2) e) print(name1>=name2)
f) print(name1<=name2)

Q14. Find out the output of the following statements
values =’aeiouAEIOU’
a) if ‘a’ in values :
print(‘True’)
else:
print(‘ false’)

b) if ‘a’ not in values :
print(‘True’)
else:
print(‘ false’)

Q15. find out the output of the following program
Str1= “Python Programming”
Str2=””
For x in range(len(str1)):
Str2=str2+str1[x]
Print(str2)

Q16. find out the output of the following program segment
Str1 =”PythonFun”
For x in str1:
Print(x)
Print(x,end=’ ‘)
Print(x, end= ‘#’)

Q17. Write the code to print the following on the screen. Suppose a string str1 contains ‘Python fun’
a) fun
b) Python

Q18. what is the difference between lower() and islower() in context to Python String.

Q19. Write the output of the following questions. Suppose a string str1 contains ‘PythonFun’
a) str1.islower()
b) str1.isupper()
c) str1.isdigit()
d) str1.isspace()
e) str1.isdigit()
f) str1.isalpha()

Q20. find out the output of the following ( assume # represent an space)
Str1 =”####Python## functions ####
a) Print(lstrip(str1))
b) Print(rstrip(str1))
c) Print(strip(str1))
d) Print(len(strip(str1)))

Q21.Write a python program to read a string from the keyboard. Print this string in reverse order.

Q22. write a python program to read a string from the keyboard. Check this string for palindrome. A palindrome string reads the same from the both ends.
Example of palindrome string: NITIN, RADAR, MADAM

Q23. Write a Python program to read a string from the keyboard. Display each word of this string along with its length.

Q24. write a program in python to read a string from the keyboard. Display the same string with the capital letter of each word of this string.
Example: this is me and this is my program
Result: This Is Me And This Is My Program

Q25. Write a program in Python to read a string from the keyboard. Replace each ‘this’ word with ‘that word’ in this
String.
Example: this is me and this is my python program.
Output: That is me and That is my python program.

Q26. Write a program in Python to read a string from the keyboard. Remove the word ‘ this’ from this string.
Example : this is me and this is my python program.
Result : is me and is my python program.

Q27. write a program in python to read a string. Find out the total number of words available in this string.

Q28. Write a program in Python to find out total number of digits, capital letters and small letters available in this string.
Q29. Write a python program to read a string from keyboard. Print the pattern as per the example.
Example : string – PythonFun
Output
P
Py
Pyt
Pyth
Python
PythonF
PythonFu
PythonFun
Q30. Write a python program to read a string from keyboard. Print each character of this string on a separate line using while loop only.
Q31. Write a python program to read a string from keyboard. Find out the length of this string without using len( ) function.

If you like CBSEToaday and would like to contribute, you can also write an article using submit article or mail your article to contribute@cbsetoday.com See your article appearing on the cbsetoday.com main page and help other students/teachers.