Module quiz: Basic Programming with Python - Module 2

Module quiz: Basic Programming with Python - Module 2

  1. Which of the following is not a sequence data-type in Python?

    • Dictionary

    • List

    • Tuples

    • String

  2. For a given list called new_list, which of the following options will work:

    new_list = [1,2,3,4]

    Select all that apply.

    • new_list[4] = 10

    • new_list.extend(new_list)

    • new_list.insert(0, 0)

    • new_list.append(5)

  3. Which of the following is not a type of variable scope in Python?

    • Local

    • Global

    • Enclosing

    • Package

  4. Which of the following is a built-in data structure in Python?

    • Queue

    • Set

    • LinkedList

    • Tree

  5. For a given file called ‘names.txt’, which of the following is NOT a valid syntax for opening a file:

    • with open('names.txt', 'r') as file:

      print(type(file))

    • with open('names.txt', 'w') as file:

      print(type(file))

    • with open('names.txt', 'rb') as file:

      print(type(file))

    • with open('names.txt', 'rw') as file:

      print(type(file))

  6. Which among the following is not a valid Exception in Python?

    • ZeroDivisionException

    • FileNotFoundError

    • IndexError

    • LoopError

  7. For a file called name.txt containing the lines below:

     First line
     Second line
     And another !
    

    What will be the output of the following code:

     print(lines)
     with open('names.txt', 'r') as file:
     lines = file.readlines()
    
    • 'First line'

    • [‘First line\n’,

      ‘Second line\n’,

      ‘And another !’]

    • ['First line']

    • 'First line'

      'Second line'

      'And another !'

  8. State TRUE or FALSE:

    *args passed to the functions can accept the key-value pair.

    • True

    • False