Python Online Test

10 Questions | Total Attempts: 2257

SettingsSettingsSettings
Python Online Test - Quiz

Take up this Python online test and check your knowledge of programming in the python language. Also, you'd be able to check your learning progress in this programming language. Python is a high-level and powerful general-purpose programming language and is used in web development and data science. The quiz contains some basic questions related to the Python language. Want to test your coding skills? If yes, play the quiz below and assess for yourself. Best of luck, buddy!


Questions and Answers
  • 1. 
    Given the file dog_breeds.txt, which of the following is the correct way to open the file for reading as a text file?
    • A. 

      Open('dog_breeds.txt', 'rb')

    • B. 

      Open('dog_breeds.txt', 'w')

    • C. 

      Open('dog_breeds.txt', 'wb')

    • D. 

      Open('dog_breeds.txt')

  • 2. 
    Given the file jack_russell.png, which of the following is the correct way to open the file for reading as a binary file?
    • A. 

      Open('jack_russell.png', 'wb')

    • B. 

      Open('jack_russell.png', 'r')

    • C. 

      Open('jack_russell.png', 'rb')

    • D. 

      Open('jack_russell.png')

  • 3. 
    Whenever possible, what is the recommended way to ensure that a file object is properly closed after usage?
    • A. 

      By using the try/finally block

    • B. 

      By using the with statement

    • C. 

      It doesn’t matter

    • D. 

      By using the if/else statement

  • 4. 
    When reading a file using the file object, what method is best for reading the entire file into a single string?
    • A. 

      .readline()

    • B. 

      .read()

    • C. 

      .readlines()

    • D. 

      .read_file_to_str()

  • 5. 
    Consider the following sequence of statements: n = 300 m = n Following execution of these statements, Python has created how many objects and how many references?
    • A. 

      One object, one reference

    • B. 

      Two object, one reference

    • C. 

      One object, two reference

    • D. 

      Two object, two reference

  • 6. 
    Which of the following are valid Python variable names:
    • A. 

      Ver1.3

    • B. 

      Return

    • C. 

      6root66

    • D. 

      Home_address

  • 7. 
    Which of the following are Python reserved words (keywords):
    • A. 

      Goto

    • B. 

      Default

    • C. 

      And

    • D. 

      Class

  • 8. 
    What is the value of the expression 100 / 25?
    • A. 

      4.0

    • B. 

      3.0

    • C. 

      4.5

    • D. 

      5.0

  • 9. 
    Using the same directory structure as before: animals/ │ ├── feline/ ← cwd │ ├── lions.gif │ └── tigers.gif │ ├── ursine/ │ └── bears.gif │ └── animals.csv Assuming that the current working directory(cwd) is in the feline folder, what is the relative path to the file bears.gif?
    • A. 

      ../ursine/bears.path

    • B. 

      ../ursine/bears.jif

    • C. 

      ../ursine/bears.gif

    • D. 

      None

  • 10. 
    In Python, a variable must be declared before it is assigned a value:
    • A. 

      Somewhat true

    • B. 

      Somewhat false

    • C. 

      Not clear

    • D. 

      None

Related Topics