Python Code Comprehension Quiz Quiz

  1. List Concatenation

    How do you concatenate two lists in Python?

    1. Using the `append()` method only.
    2. Using the `join()` method.
    3. Using the `+` operator or the `extend()` method.
    4. Using the `concat()` function.
    5. Using the `add()` method.
  2. Loop Differences

    When should you use a 'while' loop instead of a 'for' loop in Python?

    1. When iterating over a predefined sequence.
    2. When you only have an end condition and don’t know exactly how many times it will repeat.
    3. When you want to iterate in reverse order.
    4. When you know the exact number of iterations.
    5. while loops aren't usable in python
  3. Floor Function

    Which function is used to get the largest integer less than or equal to a given number in Python?

    1. math.ceiling()
    2. math.round()
    3. math.floor()
    4. math.trunc()
    5. math.integer()
  4. Division Operators

    What is the difference between the `/` and `//` operators in Python?

    1. / is for integer division, // is for float division
    2. / returns an integer, // returns a float
    3. / represents precise division, // represents floor division
    4. / represents floor division, // represents precise division
    5. There is no diffrence
  5. Indentation Importance

    Is indentation required in Python, and if so, why?

    1. No, indentation is just for readability.
    2. Yes, indentation defines code blocks.
    3. Only for functions, not loops.
    4. Only for classes, not functions.
    5. Only for comments
  6. Functions as Arguments

    Can a function be passed as an argument to another function in Python?

    1. No, functions can only return values.
    2. Yes, because functions are objects.
    3. Only if the function is defined within the same file.
    4. Only if the function is a lambda function.
    5. No, functions can't be arguments
  7. Dynamic Typing

    What does it mean for Python to be a dynamically typed language?

    1. Data types must be declared manually before use.
    2. Data types are checked at compile time.
    3. The data type of a variable is determined at runtime.
    4. Python isn't dynamically typed.
    5. Data types can never be changed
  8. Pass Statement

    What is the purpose of the 'pass' statement in Python?

    1. To skip to the next iteration of a loop.
    2. To terminate the program.
    3. To define an empty function or block.
    4. To declare a variable.
    5. To return a value
  9. Argument Passing

    How are arguments passed in Python, and is it by value or by reference?

    1. Always by value.
    2. Always by reference.
    3. By object reference, behaving like pass-by-value for immutable objects and pass-by-reference for mutable objects.
    4. By pointer.
    5. by copy
  10. Lambda Functions

    What is a lambda function in Python?

    1. A function with a specific name.
    2. An anonymous function that can have multiple statements.
    3. An anonymous function that can have any number of parameters, but only one statement.
    4. A function that only accepts integer arguments.
    5. A build in function
  11. List Concatenation shorthand

    Which of the following operations will result in a new concatenated list?

    1. list1.extend(list2)
    2. list1.append(list2)
    3. list1 = list1 + list2
    4. list1.concat(list2)
    5. list1.add(list2)
  12. While Loop Condition

    What is the most important consideration when using a 'while' loop to prevent infinite loops?

    1. Ensuring the loop variable is decremented correctly.
    2. Ensuring the loop condition eventually becomes false.
    3. Ensuring the loop contains at least one statement.
    4. Ensuring the loop variable is properly initialized.
    5. Ensurring it doesn't repeat more than 10 times
  13. Ceiling Function

    Which function will give you the smallest integer greater than or equal to a given number?

    1. math.floor()
    2. math.ceil()
    3. math.round()
    4. math.truncate()
    5. math.absolute()
  14. Division by zero

    What is the result of dividing a number by zero?

    1. It returns zero.
    2. It returns null.
    3. It raises a ZeroDivisionError.
    4. It returns infinity.
    5. It returns 1
  15. Code block indicator

    Which character is commonly used to define a code block in Python, often preceding an indented section?

    1. ; (semicolon)
    2. : (colon)
    3. { (curly brace)
    4. ( (parenthesis)
    5. [ (square bracket)
  16. Function with arguments

    If I want to pass one function to another, what data type would that parameter be?

    1. A string
    2. An integer
    3. A function
    4. A boolean
    5. A float
  17. Data Typing

    What other languages are similar to Python in that they are dynamically typed?

    1. Java
    2. C++
    3. C
    4. Javascript
    5. Cobol
  18. Code placeholder

    What is another name for the 'pass' statement?

    1. A function
    2. A placeholder
    3. A variable
    4. An argument
    5. A constant
  19. Passing Arguments

    Which is not a correct way of passing arguments to a function?

    1. call by value
    2. call by reference
    3. call by object
    4. call by object reference
    5. call by named reference
  20. Lambda shorthand

    What symbol is used in the definition of the lambda function?

    1. def
    2. lambda
    3. return
    4. pass
    5. class