Python Syntax Rules Flashcards
Learn syntax rules for Python
What is the correct way to start a Python comment?
Using the ‘#’ symbol.
True or False: In Python, indentation is used to define the scope of loops and functions.
True.
Fill in the blank: A Python variable name cannot start with a _______.
Number.
What symbol is used to denote the beginning of a block of code in Python?
Colon (:).
Which of the following is a valid variable name in Python? a) 1st_var, b) var_1, c) var-1
b) var_1.
True or False: Python is case-sensitive.
True.
What do you use to create a list in Python?
Square brackets []
What is the purpose of the ‘def’ keyword in Python?
To define a function.
What is the output of the expression ‘3 * 2 ** 2’ in Python?
12.
Fill in the blank: The _______ function is used to read input from the user.
input.
Which of the following is a built-in data type in Python? a) String, b) Array, c) List
a) String.
What keyword is used to create a conditional statement in Python?
if.
True or False: The ‘else’ clause must always be used after an ‘if’ statement.
False.
What is the result of ‘5 == 5’ in Python?
True.
What symbol is used for the modulo operation in Python?
%
What is the purpose of the ‘return’ statement in a function?
To return a value from the function.
Which of the following is a valid way to create a dictionary in Python? a) dict = {}, b) dict = [], c) dict = ()
a) dict = {}.
Fill in the blank: The _______ keyword is used to handle exceptions in Python.
try.
What is the output of ‘len([1, 2, 3])’ in Python?
3.
True or False: Lists in Python are mutable.
True.
What is the correct way to define a class in Python?
Using the ‘class’ keyword.
What does the ‘pass’ statement do in Python?
It acts as a placeholder and does nothing.
Which of the following is a comparison operator? a) +, b) ==, c) *
b) ==.
What is the output of ‘bool(0)’ in Python?
False.