Public24 cardsby @donk

Python Fundamentals

Syntax, data types, lists, dictionaries, tuples, sets, control flow, functions, classes, and common standard library modules.

Cards (24)

  • 1
    Front

    What is the correct way to write a comment in Python?

    Back

    Use the # symbol. Everything after # on that line is ignored by the interpreter. Example: # This is a comment

  • 2
    Front

    What are the five built-in numeric data types in Python?

    Back

    int (integer), float (floating-point), complex (complex numbers), bool (boolean, a subtype of int), and NoneType (representing None).

  • 3
    Front

    How does Python use indentation in its syntax?

    Back

    Python uses indentation (typically 4 spaces) to define code blocks instead of braces. Incorrect indentation causes an IndentationError.

  • 4
    Front

    What is the difference between a Python list and a tuple?

    Back

    Lists are mutable (can be changed after creation) and use square brackets []. Tuples are immutable (cannot be changed) and use parentheses ().

  • 5
    Front

    How do you create an empty dictionary in Python?

    Back

    Use empty curly braces: my_dict = {} or the dict() constructor: my_dict = dict().

  • 6
    Front

    What makes a Python set unique compared to lists and tuples?

    Back

    A set stores only unique elements, is unordered, and is mutable. It does not support indexing or slicing.

  • 7
    Front

    How do you access a value in a dictionary by its key?

    Back

    Use 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.

  • 8
    Front

    What is list slicing in Python and what is its syntax?

    Back

    List slicing extracts a sub-list. Syntax: list[start:stop:step]. Example: my_list[1:4] returns elements at indices 1, 2, and 3.

  • 9
    Front

    What is the syntax for a Python for loop iterating over a list?

    Back

    for item in my_list:
    # do something with item
    The loop runs once for each element in the list.

  • 10
    Front

    What is the purpose of the 'elif' keyword in Python control flow?

    Back

    elif (else-if) provides additional conditions to check if the preceding if or elif condition was False. It chains multiple conditional branches.

  • 11
    Front

    What is the syntax for defining a function in Python?

    Back

    Use the def keyword followed by the function name, parentheses for parameters, and a colon. Example:
    def my_func(param):
    return param

  • 12
    Front

    What is a default parameter value in a Python function?

    Back

    A default value assigned to a parameter in the function definition, used when the caller does not provide that argument. Example: def greet(name='World'):

  • 13
    Front

    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.

  • 14
    Front

    What is a lambda function in Python?

    Back

    A lambda is an anonymous, single-expression function defined with the lambda keyword. Example: square = lambda x: x ** 2

  • 15
    Front

    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.

  • 16
    Front

    What is the role of 'self' in a Python class method?

    Back

    self 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.

  • 17
    Front

    How do you create a subclass in Python?

    Back

    Pass the parent class as an argument in the class definition. Example:
    class Dog(Animal):
    pass
    Dog inherits all attributes and methods of Animal.

  • 18
    Front

    What does the Python 'os' module provide?

    Back

    The 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).

  • 19
    Front

    What is the primary use of the Python 'sys' module?

    Back

    The sys module provides access to interpreter-related variables and functions, such as sys.argv (command-line arguments), sys.exit(), and sys.path.

  • 20
    Front

    What does the Python 'math' module include?

    Back

    The math module provides mathematical functions and constants such as math.sqrt(), math.pi, math.floor(), math.ceil(), and math.log().

  • 21
    Front

    What is a Python list comprehension and what is its syntax?

    Back

    A 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]

  • 22
    Front

    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).

  • 23
    Front

    How does a while loop differ from a for loop in Python?

    Back

    A 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.

  • 24
    Front

    What does the 'datetime' module's datetime.now() function return?

    Back

    It 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.