Beginner Flashcards
What is the correct file extension for Python files?
.py
True or False: Python is a statically typed language.
False
Fill in the blank: In Python, a ___ is a sequence of characters enclosed in quotes.
string
What keyword is used to define a function in Python?
def
Which of the following is a mutable data type in Python? (a) Tuple (b) List (c) String
b) List
What is the output of the expression 3 * ‘hello’?
‘hellohellohello’
True or False: Python uses indentation to define blocks of code.
True
What is the purpose of the ‘self’ keyword in Python class methods?
It refers to the instance of the class.
What built-in function can be used to get the length of a list?
len()
What is the output of print(type([])) in Python?
<class ‘list’>
Which symbol is used for comments in Python?
#
What does the ‘pass’ statement do in Python?
It is a null statement; it does nothing.
What are the two main types of loops in Python?
for loop and while loop
What is a dictionary in Python?
A collection of key-value pairs.
True or False: Python supports multiple inheritance.
True
Multiple inheritance is a feature in Python that allows a class to inherit from more than one parent class. This means a child class can derive attributes and methods from multiple base classes.
Eg.
class Child(Parent1, Parent2):
What is the purpose of the ‘import’ statement in Python?
To include external modules or libraries.
Which method is used to add an element to the end of a list?
append()
What is the difference between ‘==’ and ‘is’ in Python?
’==’ checks for value equality, ‘is’ checks for identity.
What will be the output of the expression 5 // 2?
And what is the operator?
2
// is the floor division operator, it divides the left by the right and rounds the answer down to the nearest integer, discarding the decimal
What is a lambda function in Python?
An anonymous function defined with the lambda keyword.
What function is used to read input from the user in Python?
input()
What is list comprehension in Python?
A concise way to create lists using a single line of code.
It allows you to create a new list by applying an an expression to each element in a list using an interable
Eg:
Squared = [2 ** x for x in numbers]
What does the ‘break’ statement do in a loop?
It exits the loop immediately.
What is the purpose of the ‘try’ and ‘except’ blocks in Python?
To handle exceptions and errors.