← All POC Flashcard Decks

Core Python Programming Concepts Flashcards

9 cards from real POC practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 9 Core Python Programming Concepts flashcards as text
  1. What is the correct way to create a variable in Python?

    Answer: x = 10

    In Python, variables are created simply by assigning a value to a name using the assignment operator `=`. Python is dynamically typed, meaning you don't need to declare the variable's type explicitly. The interpreter infers the type based on the assigned value.

  2. What is the output of: print(type(3.14))?

    Answer:

    The `type()` function in Python returns the type of the object passed to it. The number `3.14` contains a decimal point, which Python recognizes as a floating-point number. Therefore, `print(type(3.14))` outputs ``, indicating its data type.

  3. Which keyword is used to define a function in Python?

    Answer: def

    In Python, the `def` keyword is used to define a function. It stands for "define" and is followed by the function name, parentheses for parameters, and a colon, signaling the start of the function's code block. This keyword is fundamental for creating reusable blocks of code.

  4. Which of the following is a list in Python?

    Answer: [1, 2, 3]

    In Python, a list is a mutable, ordered sequence of elements enclosed in square brackets `[]`. It can hold items of different data types and is one of the most versatile collection types. Options A, C, and D represent a set, a tuple, and an invalid syntax respectively.

  5. What does the 'len()' function do?

    Answer: It returns the length of an object

    The built-in `len()` function in Python is used to determine the number of items in an object. It can be applied to various sequence types like strings, lists, tuples, dictionaries, and sets, returning the count of their respective elements. This is useful for checking the size of collections.

  6. Which operator is used for exponentiation in Python?

    Answer: **

    In Python, the double asterisk `**` operator is used for exponentiation, meaning "to the power of." For example, `2 ** 3` would calculate 2 raised to the power of 3, resulting in 8. This operator provides a concise way to perform power calculations.

  7. Which loop is used to iterate over a sequence in Python?

    Answer: for

    The `for` loop in Python is specifically designed to iterate over the elements of a sequence (like a list, tuple, string, or range) or other iterable objects. It executes a block of code for each item in the sequence, making it ideal for processing collections of data.

  8. What does the 'break' keyword do in a loop?

    Answer: Exits the loop

    The `break` keyword in Python is used to terminate the current loop prematurely. When `break` is encountered inside a `for` or `while` loop, the loop immediately stops, and program execution continues with the statement immediately following the loop. It's often used to exit a loop based on a specific condition.

  9. Which data type is used to store True or False values?

    Answer: bool

    The `bool` (Boolean) data type in Python is used to represent logical values, which can only be `True` or `False`. These values are fundamental for conditional statements and logical operations, controlling program flow based on truthiness. They are essential for decision-making in programs.