Any2Quiz
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.

Play all 43 questions free

Sample questions

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

    1. 2_variable
    2. _my_var
    3. my-variable
    4. my variable
    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?

    1. float
    2. boolean
    3. string
    4. array
    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?

    1. class
    2. new
    3. define
    4. object
    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?

    1. `my_set = (1, 2, 3)`
    2. `my_set = [1, 2, 3]`
    3. `my_set = {1, 2, 3}`
    4. `my_set = {1: 'a', 2: 'b'}`
    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('')`?

    1. True
    2. False
    3. None
    4. Error
    Show answer

    Answer: B. False

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

Take the full quiz

More quizzes

Browse all Python quizzes