1. Which of the following is immutable in Python?
A. list B. string C. dict D. set
2. What is the output of type("Hello")?
A. str B. list C. int D. tuple
3. How do you access the first character of a string s?
A. s[0] B. s[1] C. s[-1] D. [Link]()
4. Which operator can be used to concatenate two strings?
A. + B. * C. % D. //
5. What does "Hello"[1:4] return?
A. 'Hel' B. 'ell' C. 'llo' D. 'Hlo'
6. Output of "Python"*2?
A. 'PythonPython' B. 'Python2' C. 'Python*2' D. Error
7. Which method converts a string to uppercase?
A. upper() B. capitalize() C. title() D. lower()
8. Which method converts a string to lowercase?
A. lower() B. upper() C. swapcase() D. capitalize()
9. How can you check if a string starts with a substring?
A. startswith() B. beginswith() C. isstart() D. start()
10. Which method removes whitespaces from the beginning and end of a string?
A. strip() B. trim() C. clean() D. remove()
11. What does "Hello".find('e') return?
A. 1 B. 2 C. 0 D. -1
12. Output of "Hello World".split()?
A. ['Hello', 'World'] B. 'Hello World' C. ['H','e','l','l','o'] D. Error
13. Which method replaces a substring in a string?
A. replace() B. swap() C. change() D. substitute()
14. What does "abc".isalpha() return?
A. True B. False C. Error D. None
15. Output of "123".isdigit()?
A. True B. False C. Error D. None
16. Can strings be nested inside lists?
A. Yes B. No C. Only numeric D. Only tuples
17. Which operator repeats a string n times?
A. * B. + C. % D. //
18. What does "hello".capitalize() return?
A. 'Hello' B. 'hello' C. 'HELLO' D. 'HelloWorld'
19. Output of " python ".strip()?
A. 'python' B. ' python' C. 'python ' D. ' python '
20. Can strings be used as dictionary keys?
A. Yes B. No C. Only numeric D. Only tuples
21. What is the output of "Python"[::-1]?
A. 'nohtyP' B. 'Python' C. Error D. 'Python'
22. Which method returns the number of times a substring occurs?
A. count() B. index() C. find() D. length()
23. Output of "Python".index('y')?
A. 1 B. 2 C. 0 D. Error
24. Which function converts other types to string?
A. str() B. string() C. toString() D. convert()
25. What does "hello".swapcase() return?
A. 'HELLO' B. 'Hello' C. 'HELLO' if lowercase D. 'HELLO'
26. Output of "Hello\nWorld"?
A. Hello
World B. Hello World C. Hello\nWorld D. Error
27. What is returned by "Python".startswith('Py')?
A. True B. False C. Error D. None
28. Output of "Python".endswith('on')?
A. True B. False C. Error D. None
29. Which method checks if a string is alphanumeric?
A. isalnum() B. isalpha() C. isdigit() D. isnumeric()
30. Output of "Py@123".isalnum()?
A. False B. True C. Error D. None
31. What does " ".join(['Hello','World']) return?
A. 'Hello World' B. 'HelloWorld' C. ['Hello','World'] D. Error
32. Which method removes only trailing spaces?
A. rstrip() B. lstrip() C. strip() D. clean()
33. Which method removes only leading spaces?
A. lstrip() B. rstrip() C. strip() D. clean()
34. Output of "Python".isupper()?
A. False B. True C. Error D. None
35. Output of "PYTHON".isupper()?
A. True B. False C. Error D. None
36. What is the output of "Python".islower()?
A. False B. True C. Error D. None
37. Output of "python".islower()?
A. True B. False C. Error D. None
38. Can strings contain special characters?
A. Yes B. No C. Only letters D. Only numbers
39. Which operator checks substring existence?
A. in B. not C. contains D. include
40. Output of 'a' in 'cat'?
A. True B. False C. Error D. None
41. Output of 'z' not in 'cat'?
A. True B. False C. Error D. None
42. Can strings be nested in tuples?
A. Yes B. No C. Only numeric D. Only lists
43. Output of "Python".title()?
A. 'Python' B. 'Python' C. 'PYTHON' D. Error
44. Output of "Python Programming".split(' ')?
A. ['Python','Programming'] B. ['Python Programming'] C. 'Python
Programming' D. Error
45. Which method replaces all occurrences of a substring?
A. replace() B. change() C. swap() D. remove()
46. Output of "Hello World".replace('World','Python')?
A. 'Hello Python' B. 'Hello World' C. 'Python' D. Error
47. Which method removes both leading and trailing whitespaces?
A. strip() B. lstrip() C. rstrip() D. clean()
48. Can a string be empty?
A. Yes B. No C. Only None D. Only 0
49. Output of "123abc".isalnum()?
A. True B. False C. Error D. None
50. Which of the following is immutable?
A. string B. list C. dict D. set
Output-Based Questions – Python Strings
1. What will be the output of:
s = "Hello"
print(s[0])
2. Predict the output:
s = "Python"
print(s[-1])
3. Output of:
s = "Python"
print(s*2)
4. Find the output:
s = "Hello"
print(s + " World")
5. What will be printed by:
s = "Python"
print(s[1:4])
6. Predict the output:
s = "Python"
print(len(s))
7. Output of:
s = "Hello"
print([Link]())
8. What is printed by:
s = "HELLO"
print([Link]())
9. Output of:
s = " Python "
print([Link]())
10. Predict the output:
s = "Hello World"
print([Link]())
11. What does "Python".replace("Py","Ja") return?
s = "Python"
print([Link]("Py","Ja"))
12. Output of:
s = "Hello"
print([Link]("He"))
13. Output of:
s = "Hello"
print([Link]("lo"))
14. What is returned by:
s = "Python"
print([Link]("t"))
15. Output of:
s = "Python"
print([Link]("o"))
16. What will "123".isdigit() return?
s = "123"
print([Link]())
17. Output of:
s = "abc"
print([Link]())
18. Predict the output:
s = "Hello World"
print("World" in s)
19. Output of:
s = "Python"
print(s[::-1])
20. What is printed by:
s = "Python"
print(s[::2])
21. Output of:
s = "Python"
print(s[1::2])
22. Predict the output:
s = "Hello World"
print([Link]("World","Python"))
23. Output of:
s = "Python"
print([Link]())
24. What does "Hello World".split('o') return?
s = "Hello World"
print([Link]('o'))
25. Output of:
s = "Hello World"
print([Link]())