Basic Python Flashcards
(27 cards)
What is the correct file extension for Python files?
.py
True or False: Python is a compiled language.
False
Fill in the blank: In Python, a _____ is used to store multiple items in a single variable.
list
What keyword is used to define a function in Python?
def
Which of the following is a valid variable name in Python? (a) 1variable (b) variable_1 (c) variable-1
b
What function would you use to get user input in Python?
input()
What is the output of print(2 ** 3)?
8
True or False: Python uses indentation to define blocks of code.
True
What is the purpose of the ‘if’ statement in Python?
To execute a block of code conditionally.
What data type is used to represent a true or false value in Python?
bool
Fill in the blank: A _____ is a collection of key-value pairs in Python.
dictionary
What operator is used for equality comparison in Python?
==
Which of the following methods can be used to add an item to a list? (a) add() (b) append() (c) insert()
b and c
What is the output of print(type(5))?
<class ‘int’>
True or False: A tuple is mutable.
False
What is the purpose of a loop in Python?
To execute a block of code repeatedly.
What keyword is used to exit a loop prematurely?
break
Fill in the blank: The _____ function is used to convert a string to an integer.
int()
What is the output of print(‘Hello’ + ‘ World’)?
Hello World
Which of the following is not a valid Python data type? (a) list (b) number (c) string
b
What is the purpose of the ‘return’ statement in a function?
To return a value from the function.
What is the correct way to import a module in Python?
import module_name
True or False: Python supports multiple inheritance.
True
What does the ‘len()’ function do?
Returns the length of an object.