Exit Chapter 02 ยท ๐Ÿ Python Revision Tour II โ€” Quiz

Playing as a guest? to earn XP and track your progress.

Question 1 of 53 0 correct so far

๐Ÿ Python Revision Tour II Quiz

Q1.

Strings in Python are:

Explanation

Strings cannot be modified after creation, hence immutable.

Q2.

What will be the output?

s = 'hello'
s[0] = 'H'
Explanation

Strings do not support item assignment, so it throws TypeError.

Q3.

Which operator is used to check if a substring exists in a string?

Explanation

The 'in' operator checks membership in strings.

Q4.

What is the output?

print('ab' * 3)
Explanation

String repetition repeats the string 3 times.

Q5.

Which slicing gives the reverse of string s?

Explanation

s[::-1] reverses a string by using negative step.

Q6.

Which method converts string to lowercase?

Explanation

lower() returns string in lowercase.

Q7.

What is the output?

print('Python'.find('th'))
Explanation

'th' begins at index 2 in 'Python'.

Q8.

Which of the following will split string based on spaces?

Explanation

split() splits string into list based on spaces by default.

Q9.

What does strip() do?

Explanation

strip() removes extra spaces from both ends.

Q10.

Output?

print('hello world'.replace('world','CBSE'))
Explanation

replace() changes substring with new value.

Q11.

Which of the following is a valid list?

Explanation

Lists use square brackets.

Q12.

Lists in Python are:

Explanation

Lists are mutable and can be modified.

Q13.

What is the output?

lst = [1,2,3]
lst.append(4)
print(lst)
Explanation

append() adds item to end.

Q14.

Which method removes the last element from a list?

Explanation

pop() removes and returns last element.

Q15.

What is the output?

lst = [10,20,30]
lst.insert(1,15)
print(lst)
Explanation

insert(index,value) inserts at given index.

Q16.

Which creates a copy of a list?

Explanation

a.copy() and copy(a) both create independent copies.

Q17.

Output?

lst = [1,2,3,4]
print(lst[1:3])
Explanation

Slice from index 1 to 2 โ†’ [2,3].

Q18.

Which of these statements is TRUE about lists?

Explanation

Lists support multiple data types.

Q19.

Which function returns number of elements in list?

Explanation

len() returns count of elements.

Q20.

Output?

print(sum([1,2,3]))
Explanation

sum() adds all numeric elements.

Q21.

Tuples in Python are:

Explanation

Tuples cannot be changed after creation.

Q22.

Which of the following is a tuple?

Explanation

Tuples use parentheses.

Q23.

What is the output?

t = (1,2,3)
print(t[1])
Explanation

Index 1 โ†’ element 2.

Q24.

Which is NOT allowed on tuples?

Explanation

Tuples are immutable; no append.

Q25.

Output?

t = (1,2,2,3)
print(t.count(2))
Explanation

2 appears twice.

Q26.

Which statement is TRUE for tuples?

Explanation

Tuples support nested elements.

Q27.

Output?

print((1,2)+(3,4))
Explanation

Tuple concatenation creates a new tuple.

Q28.

Which function converts list to tuple?

Explanation

tuple(list) converts list to tuple.

Q29.

Tuples are faster than lists because:

Explanation

Immutability allows optimization.

Q30.

Output?

t = (10,20,30)
print(len(t))
Explanation

Length of tuple is 3.

Q31.

Dictionaries store data as:

Explanation

Dictionary stores key:value pairs.

Q32.

Which creates an empty dictionary?

Explanation

{} is empty dictionary.

Q33.

Output?

d = {'a':1, 'b':2}
print(d['a'])
Explanation

d['a'] returns value 1.

Q34.

Which method returns all keys of dictionary?

Explanation

keys() returns all keys.

Q35.

Output?

d = {'x':5}
d['y'] = 10
print(d)
Explanation

Dictionary adds new key:value pair.

Q36.

Which method removes an item by key?

Explanation

pop(key) removes key:value pair and returns value.

Q37.

Output?

print('a' in {'a':10, 'b':20})
Explanation

Checks key existence, not value.

Q38.

Which characteristic of dictionary is TRUE?

Explanation

Dictionary keys must be immutable.

Q39.

Output?

d = {'a':1, 'b':2}
print(len(d))
Explanation

Two key:value pairs exist.

Q40.

Which returns all key-value pairs?

Explanation

items() returns list of (key,value) tuples.

Q41.

What is the output?

lst = [3,1,2]
lst.sort()
print(lst)
Explanation

sort() arranges elements in ascending order.

Q42.

What is the output?

sorted([4,2,5], reverse=True)
Explanation

reverse=True gives descending order.

Q43.

Output?

lst=[1,3,2]
print(sorted(lst))
Explanation

sorted() returns a new sorted list.

Q44.

Output?

s='banana'
print(s.count('a'))
Explanation

a appears 3 times.

Q45.

Which converts list of chars into string?

Explanation

join() joins list items into string.

Q46.

Output?

print('apple' < 'banana')
Explanation

String comparison is lexicographic.

Q47.

Which removes all items from dictionary?

Explanation

clear() empties dictionary.

Q48.

Output?

d={'a':1,'b':2}
print('c' in d)
Explanation

'c' not a key, hence False.

Q49.

What is the data type of keys returned by keys()?

Explanation

keys() returns dict_keys object.

Q50.

Output?

print(list(range(2,10,2)))
Explanation

Even numbers from 2 to 8.

Q51.

Which method finds index of element in list?

Explanation

index() returns first index of given element.

Q52.

Output?

s='hello'
print(s[1:4])
Explanation

Slice from index 1 to 3.

Q53.

Which statement about strings is TRUE?

Explanation

Strings support slicing and indexing.