Python Online Test

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Resmi.grg
R
Resmi.grg
Community Contributor
Quizzes Created: 1 | Total Attempts: 2,958
Questions: 10 | Attempts: 2,964

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. 

    What is the value of the expression 100 / 25?

    • A.

      4.0

    • B.

      3.0

    • C.

      4.5

    • D.

      5.0

    Correct Answer
    A. 4.0
    Explanation
    The value of the expression 100 / 25 is 4.0 because when you divide 100 by 25, the result is 4.

    Rate this question:

  • 2. 

    In Python, a variable must be declared before it is assigned a value:

    • A.

      Somewhat true

    • B.

      Somewhat false

    • C.

      Not clear

    • D.

      None

    Correct Answer
    B. Somewhat false
    Explanation
    In Python, variables do not need to be explicitly declared before they are assigned a value. Unlike some other programming languages, Python allows variables to be created and assigned a value in a single step. This means that a variable can be created and assigned a value on the same line of code without any prior declaration. Therefore, the statement "Somewhat false" accurately reflects the fact that a variable does not necessarily need to be declared before it is assigned a value in Python.

    Rate this question:

  • 3. 

    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')

    Correct Answer
    D. Open('dog_breeds.txt')
    Explanation
    The correct way to open the file for reading as a text file is by using the "open('dog_breeds.txt')" command.

    Rate this question:

  • 4. 

    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')

    Correct Answer
    C. Open('jack_russell.png', 'rb')
    Explanation
    The correct way to open the file "jack_russell.png" for reading as a binary file is by using the "open('jack_russell.png', 'rb')" command. The 'rb' mode indicates that the file should be opened in binary mode, allowing for reading binary data from the file.

    Rate this question:

  • 5. 

    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

    Correct Answer
    B. By using the with statement
    Explanation
    The recommended way to ensure that a file object is properly closed after usage is by using the with statement. The with statement automatically takes care of closing the file object, even if an exception occurs during the execution of the code. This helps to prevent resource leaks and ensures that the file is properly closed, regardless of the outcome of the code execution.

    Rate this question:

  • 6. 

    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()

    Correct Answer
    B. .read()
    Explanation
    The .read() method is the best method for reading the entire file into a single string when using the file object. This method reads the entire contents of the file and returns it as a single string. The .readline() method reads only a single line from the file, while the .readlines() method returns a list of all the lines in the file. The .read_file_to_str() method does not exist and is not a valid method for reading a file.

    Rate this question:

  • 7. 

    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

    Correct Answer
    C. One object, two reference
    Explanation
    The given sequence of statements creates one object, which is assigned to both variables "n" and "m". Therefore, there is only one object created. However, there are two references to this object, as both variables "n" and "m" refer to the same object.

    Rate this question:

  • 8. 

    Which of the following are valid Python variable names:

    • A.

      Ver1.3

    • B.

      Return

    • C.

      6root66

    • D.

      Home_address

    Correct Answer
    D. Home_address
    Explanation
    The variable name "home_address" is a valid Python variable name because it follows the rules for naming variables in Python. Variable names in Python can consist of letters (both uppercase and lowercase), numbers, and underscores, but they cannot start with a number. In this case, "home_address" starts with a letter and only contains letters, numbers, and underscores, making it a valid variable name.

    Rate this question:

  • 9. 

    Which of the following are Python reserved words (keywords):

    • A.

      Goto

    • B.

      Default

    • C.

      And

    • D.

      Class

    Correct Answer
    D. Class
    Explanation
    "class" is a Python reserved word or keyword. It is used to define a class in Python, which is a blueprint for creating objects. The other options "goto", "default", and "And" are not Python reserved words. "goto" is not a valid keyword in Python, "default" is used in some programming languages like C++ but not in Python, and "And" is not a reserved word in Python (the correct keyword is "and" with a lowercase "a").

    Rate this question:

  • 10. 

    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

    Correct Answer
    C. ../ursine/bears.gif
    Explanation
    The correct answer is ".. /ursine/bears.gif". The ".." represents going up one level in the directory structure, so ".. /ursine" refers to the ursine folder which is located at the same level as the feline folder. Then, "bears.gif" represents the file name within the ursine folder.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Apr 06, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 18, 2020
    Quiz Created by
    Resmi.grg

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.