1. Which of the following is the correct data type for text in Python?
A) int
B) float
C) str
D) list
Answer: C) str
2. Which of the following can be used to create a string in Python?
A) Single quotes (' ')
B) Double quotes (" ")
C) Triple quotes (''' ''' or """ """)
D) All of the above
Answer: D) All of the above
3. What is the output of the following code?
s = "Python"
print(s[1])
A) P
B) y
C) t
D) h
Answer: B) y
4. What is the output of the following code?
s = "Python"
print(s[-2])
A) o
B) h
C) n
D) t
Answer: A) o
5. Which operator is used to concatenate two strings?
A) +
B) *
C) &
D) %
Answer: A) +
6. What is the output of the following code?
print("Py" * 3)
A) PyPyPy
B) Py3
C) Py Py Py
D) Error
Answer: A) PyPyPy
7. Which method converts all letters in a string to uppercase?
A) capitalize()
B) upper()
C) title()
D) casefold()
Answer: B) upper()
8. Which method converts all letters in a string to uppercase??
A) upper()
B) lower()
C) swapcase()
D) capitalize()
Answer: B) lower()
9. What is the output of the following code?
s = "python programming"
print([Link]())
A) Python programming
B) Python Programming
C) PYTHON PROGRAMMING
D) python Programming
Answer: B) Python Programming
10. Which method removes spaces from both ends of a string?
A) trim()
B) remove()
C) strip()
D) delete()
Answer: C) strip()
11. What is the output of the following code?
s = "Python"
print(len(s))
A) 5
B) 6
C) 7
D) Error
Answer: B) 6
12. Which method replaces part of a string with another string?
A) replace()
B) change()
C) modify()
D) update()
Answer: A) replace()
13. What is the output of the following code?
s = "banana"
print([Link]("a"))
A) 2
B) 3
C) 4
D) 5
Answer: B) 3
14. Which method is used to split a string into a list?
A) divide()
B) split()
C) slice()
D) partition()
Answer: B) split()
15. Which method joins a list of strings into a single string?
A) append()
B) join()
C) concat()
D) merge()
Answer: B) join()
16. What is the output of the following code?
s = "Python"
print(s[::-1])
A) Python
B) nohtyP
C) Pnohty
D) Error
Answer: B) nohtyP
17. Which method checks whether all characters in a string are alphabetic?
A) isdigit()
B) isalpha()
C) isalnum()
D) isspace()
Answer: B) isalpha()
18. Which method checks whether all characters in a string are digits?
A) isdigit()
B) isdecimal()
C) isnumeric()
D) All of the above (for digit-only strings)
Answer: D) All of the above (for digit-only strings)
19. What is the output of the following code?
s = "Python"
print([Link]("t"))
A) 1
B) 2
C) 3
D) -1
Answer: B) 2
20. What is the output of the following code?
s = "Hello"
print("H" in s)
A) True
B) False
C) Error
D) None
Answer: A) True
21. Which statement about Python strings is correct?
A) Strings are mutable.
B) Strings are immutable.
C) Strings can only contain letters.
D) Strings cannot contain numbers.
Answer: B) Strings are immutable.
1. Which of the following is the correct way to create a list in Python?
A. {1, 2, 3}
B. (1, 2, 3)
C. [1, 2, 3]
D. <1, 2, 3>
Answer: C
2. Which method adds an element to the end of a list?
A. insert()
B. append()
C. add()
D. extend()
Answer: B
3. What is the output of the following?
lst = [10, 20, 30]
print(lst[1])
A. 10
B. 20
C. 30
D. Error
Answer: B
4. Which index refers to the last element of a list?
A. 0
B. 1
C. -1
D. -2
Answer: C
5. Which method removes the last element from a list?
A. remove()
B. delete()
C. pop()
D. clear()
Answer: C
6. What is the output?
lst = [1, 2, 3]
[Link](4)
print(lst)
A. [1, 2, 3]
B. [1, 2, 3, 4]
C. [4, 1, 2, 3]
D. Error
Answer: B
7. Which method inserts an element at a specified position?
A. append()
B. insert()
C. extend()
D. add()
Answer: B
8. What is the output?
lst = [5, 10, 15]
print(len(lst))
A. 2
B. 3
C. 5
D. 15
Answer: B
9. Which operator is used to concatenate two lists?
A. *
B. +
C. &
D. %
Answer: B
10. Which method removes the first occurrence of a specified value?
A. pop()
B. delete()
C. remove()
D. discard()
Answer: C
11. What is the output?
lst = [1, 2, 3]
print(lst[-2])
A. 1
B. 2
C. 3
D. Error
Answer: B
12. Which method removes all elements from a list?
A. pop()
B. delete()
C. remove()
D. clear()
Answer: D
13. Which function returns the number of elements in a list?
A. size()
B. count()
C. len()
D. length()
Answer: C
14. What is the output?
lst = [1, 2]
[Link]([3, 4])
print(lst)
A. [1, 2]
B. [1, 2, [3, 4]]
C. [1, 2, 3, 4]
D. Error
Answer: C
15. Which method returns the index of the first occurrence of a value?
A. find()
B. search()
C. index()
D. locate()
Answer: C
16. What is the output?
lst = [2, 4, 6]
print(4 in lst)
A. True
B. False
C. None
D. Error
Answer: A
17. Which method sorts a list in ascending order?
A. arrange()
B. order()
C. sort()
D. sortedlist()
Answer: C
18. What is the output?
lst = [3, 1, 2]
[Link]()
print(lst)
A. [3, 2, 1]
B. [1, 2, 3]
C. [2, 1, 3]
D. Error
Answer: B
19. Which method reverses the order of elements in a list?
A. reverse()
B. sort(reverse=True)
C. flip()
D. invert()
Answer: A
20. What is the output?
lst = [10, 20, 30]
print(lst[0:2])
A. [10]
B. [10, 20]
C. [20, 30]
D. [10, 20, 30]
Answer: B
21. Which method creates a shallow copy of a list?
A. clone()
B. duplicate()
C. copy()
D. new()
Answer: C
22. What is the output?
lst = [1, 2, 3]
print(lst * 2)
A. [2, 4, 6]
B. [1, 2, 3, 1, 2, 3]
C. [1, 2, 3, 2]
D. Error
Answer: B
23. Which list method counts the occurrences of a value?
A. total()
B. count()
C. frequency()
D. occur()
Answer: B
24. What is the output?
lst = ['a', 'b', 'c']
print(lst[1:])
A. ['a']
B. ['b', 'c']
C. ['c']
D. Error
Answer: B
25. Which of the following statements about Python lists is true?
A. Lists are immutable.
B. Lists can store elements of different data types.
C. Lists cannot contain duplicate values.
D. Lists use parentheses ().
Answer: B