
Python Fundamentals
Syntax, data types, lists, dictionaries, tuples, sets, control flow, functions, classes, and common standard library modules.
Cards (24)
- 1Front
What is the correct way to write a comment in Python?
BackUse the # symbol. Everything after # on that line is ignored by the interpreter. Example: # This is a comment
- 2Front
What are the five built-in numeric data types in Python?
Backint (integer), float (floating-point), complex (complex numbers), bool (boolean, a subtype of int), and NoneType (representing None).
- 3Front
How does Python use indentation in its syntax?
BackPython uses indentation (typically 4 spaces) to define code blocks instead of braces. Incorrect indentation causes an IndentationError.
- 4Front
What is the difference between a Python list and a tuple?
BackLists are mutable (can be changed after creation) and use square brackets []. Tuples are immutable (cannot be changed) and use parentheses ().
- 5Front
How do you create an empty dictionary in Python?
BackUse empty curly braces: my_dict = {} or the dict() constructor: my_dict = dict().
- 6Front
What makes a Python set unique compared to lists and tuples?
BackA set stores only unique elements, is unordered, and is mutable. It does not support indexing or slicing.
- 7Front
How do you access a value in a dictionary by its key?
BackUse bracket notation: my_dict['key'], or the .get() method: my_dict.get('key') which returns None if the key is missing instead of raising a KeyError.
- 8Front
What is list slicing in Python and what is its syntax?
BackList slicing extracts a sub-list. Syntax: list[start:stop:step]. Example: my_list[1:4] returns elements at indices 1, 2, and 3.
- 9Front
What is the syntax for a Python for loop iterating over a list?
Backfor item in my_list:
# do something with item
The loop runs once for each element in the list. - 10Front
What is the purpose of the 'elif' keyword in Python control flow?
Backelif (else-if) provides additional conditions to check if the preceding if or elif condition was False. It chains multiple conditional branches.
- 11Front
What is the syntax for defining a function in Python?
BackUse the def keyword followed by the function name, parentheses for parameters, and a colon. Example:
def my_func(param):
return param - 12Front
What is a default parameter value in a Python function?
BackA default value assigned to a parameter in the function definition, used when the caller does not provide that argument. Example: def greet(name='World'):
- 13Front
What do *args and **kwargs represent in a Python function signature?
Back*args collects extra positional arguments into a tuple. **kwargs collects extra keyword arguments into a dictionary.
- 14Front
What is a lambda function in Python?
BackA lambda is an anonymous, single-expression function defined with the lambda keyword. Example: square = lambda x: x ** 2
- 15Front
What is the purpose of the __init__ method in a Python class?
Back__init__ is the constructor method called automatically when a new instance of a class is created. It initializes the instance's attributes.
- 16Front
What is the role of 'self' in a Python class method?
Backself refers to the current instance of the class. It must be the first parameter of every instance method and is used to access instance attributes and other methods.
- 17Front
How do you create a subclass in Python?
BackPass the parent class as an argument in the class definition. Example:
class Dog(Animal):
pass
Dog inherits all attributes and methods of Animal. - 18Front
What does the Python 'os' module provide?
BackThe os module provides functions for interacting with the operating system, such as file path manipulation (os.path), directory operations (os.listdir), and environment variables (os.environ).
- 19Front
What is the primary use of the Python 'sys' module?
BackThe sys module provides access to interpreter-related variables and functions, such as sys.argv (command-line arguments), sys.exit(), and sys.path.
- 20Front
What does the Python 'math' module include?
BackThe math module provides mathematical functions and constants such as math.sqrt(), math.pi, math.floor(), math.ceil(), and math.log().
- 21Front
What is a Python list comprehension and what is its syntax?
BackA concise way to create a list. Syntax: [expression for item in iterable if condition]. Example: [x**2 for x in range(10) if x % 2 == 0]
- 22Front
What is the difference between '==' and 'is' in Python?
Back'==' checks if two objects have the same value. 'is' checks if two variables point to the exact same object in memory (identity).
- 23Front
How does a while loop differ from a for loop in Python?
BackA while loop repeats as long as a Boolean condition remains True, whereas a for loop iterates over a defined sequence or iterable a fixed number of times.
- 24Front
What does the 'datetime' module's datetime.now() function return?
BackIt returns a datetime object representing the current local date and time, including year, month, day, hour, minute, second, and microsecond.
Study this deck free
Create a free account to flip through these flashcards, quiz yourself, play match, and track what you've mastered — or fork the deck to make it your own.