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, freeSample questions
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.
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`.
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.
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.
What is the result of `bool('')`?
Show answer
Answer: B. False
An empty string (`''`) is considered 'falsy' in Python, so `bool('')` evaluates to `False`.
More questions in this quiz
Answers and explanations are in the full quiz.
- What is the correct way to declare a constant in Python (though Python doesn't strictly enforce constants)?
- What does the `pass` statement do in Python?
- Which of these is NOT a valid Python keyword?
- What is the result of `print(type(5))`?
- Which operator is used for exponentiation in Python?
- What is the correct syntax for a single-line comment in Python?
- Which of the following is the correct way to assign a tuple to a variable?
- What keyword is used to define a function in Python?
- Which of the following is immutable in Python?
- What is the purpose of the `is` operator in Python?
- Which indentation level is typically used for code blocks in Python?
- What does the `del` keyword do in Python?
- Which of the following is a valid way to create a list in Python?
- What does the `import` statement do?
- What is the output of `print(5 // 2)`?
- What is the Python string method used to convert a string to uppercase?
- What is the scope of a variable defined inside a function?
- Which operator is used for membership testing in Python?
- What is the result of `bool(0)`?
- Which keyword is used to define a loop that iterates over a sequence?
- What is the output of `print('5' + 3)`?
- What does the `elif` keyword do in Python?
- What is the purpose of the `return` statement in a Python function?
- Which operator is used for string repetition in Python?
- What is the output of `print(not True)`?
- Which keyword is used to create an alias for a module?
- What is the data type of the result of `5 / 2`?
- What is the keyword used to define a conditional block that executes if all preceding `if` and `elif` conditions are false?
- Which method is used to add an item to the end of a list?
- What is the primary difference between a list and a tuple in Python?
- Which keyword is used to explicitly raise an exception in Python?
- What is the correct way to get the length of a string or list?
- Which symbol is used to denote a block of code in Python?
- What does the `continue` statement do in a loop?
- What is the correct way to access the first element of a list called `my_list`?
- Which of the following is a valid assignment for a boolean value?
- What is the output of `print('hello' * 2)`?
- Which of the following is used to define an anonymous function (a function without a name)?