CARVIEW |
Python Strings and Lists
Python Strings and Lists Quiz
Question 1
What will be the output of the following Python code?
print('geeks'.upper())
GEEKS
Geeks
No output
Error
Question 2
What will be the output of the following Python code snippet?
print('geeksforgeeks'.split('ee',1))
[‘g’,’ksforgeeks’]
[‘g’,’ksforg’,’ks’]
No output
Error
Question 3
What will be the output of the following Python code snippet?
print('geeksforgeeks'.split('ee'))
[‘g’,’ksforg’,’ks’]
[‘g’,’ee’,’ksforg’,’ee’,’ks’]
No output
Error
Question 4
Find the output of the python code:
list1 = range(100, 110) # statement 1
print ("index of element 105 is : ", list1.index(105)) # statement 2
index of element 105 is : 5
index of element 105 is : 6
Error
None of the above
Question 5
Find the output of the following program:
T1 = (1)
T2 = (3, 4)
T1 += 5
print(T1)
print(T1 + T2)
Type Error
(1,5,3,4)
1, TypeError
6 TypeError
Question 6
Question : Find the output of the following program:
geekCodes = [1, 2, 3, 4]
geekCodes.append([5,6,7,8])
print(geekCodes)
[1,2,3,4,5,6,7,8]
[1,2,3,4]
[1,2,3,4,[5,6,7,8]]
[1,2,3,4][5,6,7,8]
Question 7
Find the output of the below python code:
list1 = [1, 2, 3, 4, 5]
list2 = list1
list2[0] = 0
print ("list1= : ", list1) #statement 2
list1= : [0, 2, 3, 4, 5]
list1= : [1 2, 3, 4, 5]
Error
None of the above
Question 8
Find the output of the below python code:
temp = ['Geeks', 'for', 'Geeks']
arr = [i[0].upper() for i in temp]
print(arr)
['G','F','G']
['GEEKS']
[‘GEEKS’, ‘FOR’, ‘GEEKS’
Error
Question 9
What is slicing in Python?
Slicing is used to access parts of sequences like lists, tuples, and strings. The syntax of slicing is-[start:end:step]. The step can be omitted as well. When we write [start:end] this returns all the elements of the sequence from the start (inclusive) till the end-1 element. If the start or end element is negative i, it means the ith element from the end. The step indicates the jump or how many elements have to be skipped. Eg. if there is a list- [1,2,3,4,5,6,7,8]. Then [-1:2:2] will return elements starting from the last element till the third element by printing every second element.i.e. [8,6,4].
Question 10
What are the outputs of these function calls
divmod(10.5, 5)
divmod(2.4, 1.2)
(2.00, 0.50) and (2.00, 0.00
(2, 0.5) and (2, 0)
(2.0, 0.5) and (2.0, 0.0)
(2, 0.5) and (2)
There are 21 questions to complete.