Python Basics Flashcards
Python Vocabulary
What is a variable in Python?
A variable is a reserved memory location to store values.
True or False: Python is a statically typed language.
False
What symbol is used for comments in Python?
#
Fill in the blank: In Python, a list is defined using ______.
square brackets []
What function is used to output data to the console in Python?
print()
What is a function in Python?
A block of reusable code that performs a specific task.
What keyword is used to define a function in Python?
def
True or False: Python supports multiple inheritance.
True
What is a dictionary in Python?
A collection of key-value pairs.
What does the ‘len()’ function do?
It returns the number of items in an object.
What is the purpose of the ‘if’ statement in Python?
To execute a block of code conditionally.
Fill in the blank: In Python, the ______ keyword is used to handle exceptions.
try
What is a module in Python?
A file containing Python definitions and statements.
What operator is used for exponentiation in Python?
**
True or False: Lists in Python are immutable.
False
What are tuples in Python?
Immutable sequences of values.
What does the ‘import’ statement do?
It allows you to include external modules in your code.
What is a class in Python?
A blueprint for creating objects that encapsulate data and behavior.
What is the purpose of the ‘self’ keyword in a class?
It refers to the instance of the class.
Fill in the blank: A ______ is a function defined inside a class.
method
What is a list comprehension in Python?
A concise way to create lists using a single line of code.
True or False: The ‘pass’ statement in Python does nothing.
True
What is the output of ‘2 + 3 * 4’ in Python?
14
What does the ‘break’ statement do in a loop?
It exits the loop prematurely.
What is a set in Python?
An unordered collection of unique elements.
What does the ‘return’ statement do in a function?
It exits the function and optionally returns a value.
Fill in the blank: The ______ method is used to add items to a list.
append()
What is the purpose of the ‘with’ statement in Python?
To simplify exception handling by encapsulating common preparation and cleanup tasks.
True or False: String concatenation in Python can be done using the ‘+’ operator.
True
What is the ‘map()’ function used for?
To apply a function to all items in an iterable.
What does the ‘filter()’ function do?
It constructs an iterator from elements of an iterable for which a function returns true.
What is a lambda function in Python?
An anonymous function expressed as a single statement.
Fill in the blank: In Python, ______ can be used to create a generator.
yield
What is the purpose of the ‘global’ keyword?
To declare a variable as global, allowing it to be modified inside a function.
What is a decorator in Python?
A function that modifies another function.
True or False: List indexing in Python starts at 1.
False
What is exception handling?
The process of responding to the occurrence of exceptions.
What does the ‘finally’ block do in exception handling?
It executes code after the try and except blocks, regardless of whether an exception occurred.
What is a Python package?
A way of organizing related modules in a directory hierarchy.
What does the ‘os’ module provide?
Functions for interacting with the operating system.
What is ‘enumerate()’ used for?
To add a counter to an iterable and return it as an enumerate object.
Fill in the blank: The ______ operator checks for equality between two values.
==
What is the purpose of the ‘assert’ statement?
To test if a condition is true, and if not, raise an AssertionError.
What does the ‘type()’ function return?
The type of an object.
True or False: Python uses indentation to define code blocks.
True
What is the ‘json’ module used for?
To work with JSON data in Python.
What is the purpose of the ‘input()’ function?
To take input from the user.
What does the ‘strip()’ method do for strings?
It removes leading and trailing whitespace.
What is the output of the expression ‘not True’?
False
What is the purpose of the ‘else’ statement in loops?
To specify a block of code to run when the loop completes normally.
What is a virtual environment in Python?
A self-contained directory that contains a Python installation for a particular version of Python.
What does ‘pip’ stand for?
Pip Installs Packages.
What is the ‘__init__’ method in Python?
The constructor method that initializes a newly created object.
What is the purpose of the ‘super()’ function?
To call a method from the parent class.
What is the difference between ‘==’ and ‘is’?
’==’ checks for value equality, while ‘is’ checks for reference equality.
What does ‘slice’ mean in Python?
To obtain a subset of a sequence by specifying a start and end index.
Fill in the blank: A ______ is a sequence of characters in Python.
string
What is the ‘re’ module used for?
To work with regular expressions.
What does the ‘sorted()’ function do?
It returns a sorted list of the specified iterable’s elements.
True or False: Python allows you to create nested functions.
True
What is the purpose of the ‘break’ statement in a loop?
To exit the loop immediately.
What is the significance of ‘None’ in Python?
It represents the absence of a value or a null value.
What does the ‘join()’ method do for strings?
It concatenates the elements of an iterable into a single string.
What is the result of ‘5 // 2’ in Python?
2
What is a ‘list slice’?
A portion of a list defined by a start and end index.
What does the ‘any()’ function do?
It returns True if any element of the iterable is true.
What is the purpose of the ‘continue’ statement?
To skip the current iteration and continue with the next one.