Syntax Flashcards
(79 cards)
What symbol is used for comments in Python?
#
True or False: Python uses indentation to define code blocks.
True
Fill in the blank: To define a function in Python, you use the keyword _______.
def
What is the output of the following code: print(type(5))?
<class ‘int’>
Which keyword is used to create a class in Python?
class
What is the correct way to create a list in Python?
my_list = []
True or False: Python supports multiple inheritance.
True
What data type is used to store a sequence of characters in Python?
str
Which operator is used for exponentiation in Python?
**
What keyword is used to handle exceptions in Python?
try
What is the output of the following code: print(3 + 2 * 2)?
7
Which function is used to read input from the user in Python?
input()
Fill in the blank: In Python, a tuple is defined using _______.
()
What is the purpose of the ‘return’ statement in a function?
To exit the function and return a value.
What is the syntax to create a dictionary in Python?
my_dict = {}
True or False: Lists in Python are immutable.
False
What method is used to add an element to a list?
append()
Which statement is used to exit a loop in Python?
break
What is the output of the following code: print([1, 2, 3] + [4, 5])?
[1, 2, 3, 4, 5]
Fill in the blank: A set in Python is defined using _______.
{}
What does the ‘len()’ function do in Python?
Returns the length of an object.
What will be printed by the following code: print(‘Hello’ * 3)?
HelloHelloHello
Which keyword is used to define a generator in Python?
yield
What is the purpose of the ‘if __name__ == “__main__”:’ statement?
To check if the script is being run directly.