Python

Python

Test your Python knowledge with free quizzes on MyCodeSkills covering core concepts.


  1. What is the correct file extension for Python files?

    • .pt
    • .py
    • .pyt
    • .python
  2. Which symbol is used to start a comment in Python?

    • //
    • <!--
    • #
    • /* */
  3. How do you create a variable in Python?

    • var x = 10
    • let x = 10
    • int x = 10
    • x = 10
  4. What is the correct way to assign a string to a variable?

    • x = 'Hello'
    • x := Hello
    • x << 'Hello'
    • x = Hello
  5. Which of these is a data type in Python?

    • num
    • integer
    • float
    • real
  6. Which method is called when an object is created?

    • __init__()
    • __start__()
    • constructor()
    • __object__()
  7. What keyword is used to handle exceptions in Python?

    • catch
    • except
    • handle
    • error
  8. How do you open a file for reading in Python?

    • open('file', 'r')
    • open('file', 'w')
    • open('file', 'rw')
    • open('file', 'a')
  9. What will next() do on an iterator?

    • Skip first item
    • Reset the iterator
    • Return next item
    • Stop iteration
  10. What is the output of: lambda x: x+2 when called with 5?

    • 2
    • 7
    • 10
    • 5
  11. What is the primary use of decorators in Python?

    • Memory management
    • Enhancing function behavior
    • Handling errors
    • Managing classes
  12. Which symbol is used for decorators in Python?

    • &
    • %
    • @
    • #
  13. What is the return type of a generator function?

    • List
    • Iterator
    • Generator
    • Tuple
  14. Which method is used to get the next value from a generator?

    • next()
    • yield()
    • get()
    • nextval()
  15. What does the with statement ensure when opening a file?

    • Fast execution
    • Automatic exception raising
    • Automatic resource cleanup
    • Better formatting