NAME :
CLASS :
Advanced Python Quiz Grade X
DATE :
45 Questions
1. What is the output of the following piece of code when
executed in Python shell?
>>> a=("Check")*3>>> a
a) (‘Check’,’Check’,’Check’) b) * Operator not valid for tuples
c) (‘CheckCheckCheck’) d) Syntax error
2. Is the following piece of code valid?
>>> a=(1,2,3,4)>>> del a
a) No because tuple is immutable b) Yes, the entire tuple is deleted
c) No, invalid syntax for del method d) Yes, rst element in the tuple is deleted
3. What type of data is: a=[(1,1),(2,4),(3,9)]?
a) Array of tuples b) List of tuples
c) Tuples of lists d) Invalid type
4. Which of the following is true for a tuple?
a) Tup = 1,2,3 b) Tup = (""1,"2)
c) Tup = (1,2,3,4) d) None of the above
5. Suppose you have the following tuple de nition:
t = ('foo', 'bar', 'baz')
Which of the following statements replaces the second
element ('bar') with the string 'qux':
a) t[1] = 'qux' b) t(1) = 'qux'
c) t[1:1] = 'qux' d) error
6. If list=[17,23,41,10] then list.append(32) will result
a) [32,17,23,41,10] b) [17,23,41,10,32]
c) [10,17,23,32,41] d) [41,32,23,17,10]
7. Suppose list=[12,3,22,"mago","hello"], what is list[-6]
a) Error b) None
c) mango d) 12
8. L_names=['Harsh','Amit','Sahil','Viresh']min(L_names)
a) 'Harsh' b) 'Amit'
c) 'Viresh' d) None of the above
9. L_names=['Harsh','Amit','Sahil','Viresh']L_names.pop()
a) 'Harsh' b) 'Amit'
c) 'Viresh' d) None of the above
10. If L1=[2,4,8,16], L2=[32,64] what is L1+L2
a) [2,4,8,16,32,64] b) [2,4,8,16][32,64]
c) [2,4,8,16],[32,64] d) None of the above
11. If L1=[2,4,8,16] What is the result of the following
statement16 in L1
a) True b) False
12. L=[2,4,8,16,32,64] what is L[:2]
a) [2,4] b) [2,4,8]
c) 2,4 d) None of the above
13. Suppose list1 is [1, 3, 2], What is list1 * 2 ?
a) [2, 6, 4]. b) [1, 3, 2, 1, 3]
c) [1, 3, 2, 1, 3, 2] d) [1, 3, 2, 3, 2, 1]
14. To remove string “hello” from list1, we use which
command?
a) list1.remove(“hello”) b) list1.remove(hello)
c) list.remove(“hello”) d) list.remove(hello)
15. Identify the data type of T:
T = [‘A’, ‘23’, ‘92’, ‘(10,20)’]
a) List b) Dictionary
c) String d) Tuple
16. What is the output of the code?a = (33,
55)a.append(22)print(a)
a) 33 55 22 b) 335522
c) 33, 55, 22 d) Error
17. Which of the following are true of Python lists?
a) A list may contain any type of object except b) A given object may appear in a list more
another list than once
c) All elements in a list must be of the same d) These represent the same list:['a', 'b', 'c']['c',
type 'a', 'b']
e) There is no conceptual limit to the size of a
list
18. List a is de ned as follows:
a = [1, 2, 3, 4, 5]
Select all of the following statements that remove the
middle element 3 from a so that it equals [1, 2, 4, 5]:
a) a[2] = [] b) a[2:2] = []
c) del a[2] d) a.remove(3)
19. Suppose you have the following tuple de nition:
t = ('foo', 'bar', 'baz')
Which of the following statements replaces the second
element ('bar') with the string 'qux':
a) t[1] = 'qux' b) t(1) = 'qux'
c) t[1:1] = 'qux' d) It’s a trick question—tuples can’t be
modi ed.
20. Write Python code to create a tuple with a single element,
the string 'foo', and assign it to a variable called t.
21. Which of the following functions is used to count the
number of elements in a list ?
a) count( ) b) nd( )
c) len( ) d) index( )
22. Let list1=[2,4,6,8,10].What will print(list1[-2]) result in?
a) -2 b) 8
c) 4 d) 6
23. Which of the following statements is NOT correct?
a) A list is mutable b) A tuple is immutable
c) The append function is used to add an d) The extend function adds an element to a
element tuple
24. If list1=[10,20,30,40,50] then list1[2]=35 will result in:
a) [35,10,20,30,40,50] b) [10,20,30,40,50,35]
c) [10,20,35,40,50] d) [10,35,30,40,50]
25. Which of these is the correct code for creating a list of
names?
a) nameList = John, Harry, Jesse, John, Harry, b) nameList = ("John", "Harry", "Jesse", "John",
Harry "Harry", "Harry")
c) nameList = ["John", "Harry", "Jesse", "John", d) nameList = [John, Harry, Jesse, John, Harry,
"Harry", "Harry"] Harry]
26. Which of these pieces of code would return the name
"Harry" from the following list?nameList = ["John", "Harry",
"Jesse", "John", "Harry", "Harry"]
a) nameList(1) b) nameList[4]
c) nameList(4) d) nameList["1"]
27. Which of these is a correct statement?
a) List and tuples both are mutable. b) List is mutable whereas tuples are
immutable.
c) List and tuples both are immutable. d) List is immutable whereas tuples are
mutable
28. Can lists contain tuples and vice versa?
a) Yes b) No
29. Let x= "Python", the output of print(x[0])print(x[1])print(x[2])
a) PYT b) Pyt
c) Tho d) noh
30. How do you print a statement in python programming?
a) print ( " hello world ") b) print(]
c) print [ "c"] d) None of the above
31. How is a multiline comment interpreted in Python?
a) ""This is a multiline comment b) #This is a multiline comment
c) ''' This is a multiline comment''' d) None of the above
32. Which of the following is not a datatype?
a) Strings b) Numerics
c) Variable d) Tuple
33. Select a valid string in python?
a) var = " string" b) var == string
c) var =! string d) var ["string"]
34. Whats is the datatype of print(type(10))
a) Float b) Integer
c) Complex d) None of the above
35. ______ data types store values of more than one data type
a) List b) Tuple
c) Float d) Dictionary
36. Choose the immutable data type.
a) Tuples b) List
c) Set d) Dictionaries
37. Is Python case sensitive when dealing with identi ers?
a) Yes b) No
38. Mathematical operations can be performed on a string.
a) True b) False
39. Which of the following has more precedance?
a) / b) +
c) () d) -
40. Which one is NOT a legal variable name?
a) my-var b) my_var
c) Myvar d) _myvar
41. How do you create a variable with the oating number 2.8?
a) x = 2.8 b) x = oat(2.8)
c) Both the other answers are correct
42. What is the correct syntax to output the type of a variable
or object in Python?
a) print(typeof(x)) b) print(typeOf(x))
c) print(type(x)) d) print(typeof x)
43. Which operator can be used to compare two values?
a) == b) <>
c) >< d) =
44. How do you start writing an if statement in Python?
a) if x > y: b) if x > y then:
c) if (x > y)
45. Which of the following is an invalid variable?
a) my_string_1 b) b) 1st_string
c) foo d) _
Answer Key
1. c 13. c 25. c 37. a
2. b 14. a 26. b 38. b
3. b 15. a 27. b 39. c
4. a,c 16. d 28. a 40. a
5. d 17. b,e 29. b 41. c
6. b 18. c,d 30. a 42. c
7. a 19. d 31. c 43. a
8. b 20. t = ('foo',) 32. c 44. a
9. c 21. c 33. a 45. b
10. a 22. b 34. b
11. a 23. d 35. a,b,d
12. a 24. c 36. a