Simple Python Quiz

Tests basic Python programming concepts including data structures (lists, tuples, dictionaries), loops, and type checking

7 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

numbers= [1,2,3,4] numbers.append([5,6,7,8]) print len(numbers)

  1. 4
  2. 5
  3. 8
  4. 12
  5. An exception is thrown
Question 2 Multiple Choice (Single Answer)

for i in range(2): print i for i in range(4,6): print i

  1. 2, 4, 6
  2. 0, 1, 2, 4, 5, 6
  3. 0, 1, 4, 5
  4. 0, 1, 4, 5, 6, 7, 8, 9
  5. 1, 2, 4, 5, 6
Question 3 Multiple Choice (Single Answer)

foo = {1:'1', 2:'2', 3:'3'} del foo[1] foo[1] = '10' del foo[2] print len(foo)

  1. 2
  2. 7
  3. 3
  4. 4
  5. An exception is thrown
Question 4 Multiple Choice (Single Answer)

Which of the following data structures can be used with the "in" operator to check if an item is in the data structure?

  1. List
  2. Set
  3. Dictionary
  4. None of the above
  5. All of the above
Question 5 Multiple Choice (Single Answer)

my_tuple = (1, 2, 3, 4) my_tuple.append( (5, 6, 7) ) print len(my_tuple)

  1. 1
  2. 6
  3. 4
  4. 5
  5. An exception is thrown
Question 6 Multiple Choice (Single Answer)

print type([1,2]).The output is:

  1. <type 'tuple'>
  2. <type 'int'>
  3. <type 'complex'>
  4. <type 'list'>
  5. <type ‘Dictionary’>
Question 7 Multiple Choice (Single Answer)

names =['Amir', 'Barry', 'Chales', 'Dao'] print names [-1][-1] The output is:

  1. A
  2. r
  3. Amir
  4. Dao
  5. O