Any2Quiz
Quizzes / Computer Science / Languages / Python

Syntax Quiz - Languages Python

Free practice quiz: Syntax (Languages Python). 43 multiple-choice questions with answers and explanations. Play online, no sign-up needed.

This Languages Python practice quiz has 43 multiple-choice questions on Syntax, and 43 of them come with an explanation. Try the 5 sample questions below (tap an option to check yourself), then play the full quiz online. No sign-up needed.

Start quiz: 43 questions, free

Sample questions

  1. Which of the following is a valid Python variable name?

    Show answer

    Answer: B. _my_var

    Python variable names can start with a letter or an underscore, followed by letters, numbers, or underscores. They cannot start with a number, contain hyphens, or spaces.

  2. Which of the following is NOT a Python data type?

    Show answer

    Answer: D. array

    Python has built-in data types like `float` (for floating-point numbers), `bool` (for boolean values), and `str` (for strings). While Python has lists which are similar to arrays, 'array' itself is not a primary built-in data type in the same way. The `array` module exists for a more C-style array, but 'array' as a general term isn't a fundamental type like `int`, `float`, `str`, `list`, `tuple`, `dict`, `set`.

  3. Which of the following is used to define a class in Python?

    Show answer

    Answer: A. class

    The `class` keyword is used to declare a new class. It is followed by the class name and a colon. The class body, which contains attributes and methods, is indented.

  4. Which of the following is used to create a set in Python?

    Show answer

    Answer: C. `my_set = {1, 2, 3}`

    Sets in Python are unordered collections of unique elements and are defined using curly braces `{}`. If you use `{}` with key-value pairs, it creates a dictionary. `()` creates a tuple, and `[]` creates a list.

  5. What is the result of `bool('')`?

    Show answer

    Answer: B. False

    An empty string (`''`) is considered 'falsy' in Python, so `bool('')` evaluates to `False`.

Take the full quiz

More questions in this quiz

Answers and explanations are in the full quiz.

  1. What is the correct way to declare a constant in Python (though Python doesn't strictly enforce constants)?
  2. What does the `pass` statement do in Python?
  3. Which of these is NOT a valid Python keyword?
  4. What is the result of `print(type(5))`?
  5. Which operator is used for exponentiation in Python?
  6. What is the correct syntax for a single-line comment in Python?
  7. Which of the following is the correct way to assign a tuple to a variable?
  8. What keyword is used to define a function in Python?
  9. Which of the following is immutable in Python?
  10. What is the purpose of the `is` operator in Python?
  11. Which indentation level is typically used for code blocks in Python?
  12. What does the `del` keyword do in Python?
  13. Which of the following is a valid way to create a list in Python?
  14. What does the `import` statement do?
  15. What is the output of `print(5 // 2)`?
  16. What is the Python string method used to convert a string to uppercase?
  17. What is the scope of a variable defined inside a function?
  18. Which operator is used for membership testing in Python?
  19. What is the result of `bool(0)`?
  20. Which keyword is used to define a loop that iterates over a sequence?
  21. What is the output of `print('5' + 3)`?
  22. What does the `elif` keyword do in Python?
  23. What is the purpose of the `return` statement in a Python function?
  24. Which operator is used for string repetition in Python?
  25. What is the output of `print(not True)`?
  26. Which keyword is used to create an alias for a module?
  27. What is the data type of the result of `5 / 2`?
  28. What is the keyword used to define a conditional block that executes if all preceding `if` and `elif` conditions are false?
  29. Which method is used to add an item to the end of a list?
  30. What is the primary difference between a list and a tuple in Python?
  31. Which keyword is used to explicitly raise an exception in Python?
  32. What is the correct way to get the length of a string or list?
  33. Which symbol is used to denote a block of code in Python?
  34. What does the `continue` statement do in a loop?
  35. What is the correct way to access the first element of a list called `my_list`?
  36. Which of the following is a valid assignment for a boolean value?
  37. What is the output of `print('hello' * 2)`?
  38. Which of the following is used to define an anonymous function (a function without a name)?

More quizzes

Browse all Python quizzes

More to play

Daily ChallengeA new quiz every day. Keep your streak.HangmanGuess the word, letter by letter.Story QuestLearn through short interactive stories.All quizzesCBSE, ICSE, competitive exams and more.