The true mechanism behind private attributes in Python is a feature called _______.

  • abstraction
  • data hiding
  • encapsulation
  • name mangling
Python uses a technique called "name mangling" to make attributes private by adding a prefix to their names.

The _______ operator returns True if the value on its left is less than the one on its right.

  • Greater than (>)
  • Greater than or equal to (>=)
  • Less than (<)
  • Less than or equal to (<=)
The 'Less than' operator returns True if the value on its left is less than the one on its right.

To execute a Python script, which of the following commands can be used?

  • execute script.py
  • python script.py
  • run script.py
  • start script.py
To execute a Python script, you can use the command python script.py. This command runs the Python interpreter and executes the script specified after python. It's the standard way to execute Python scripts from the command line or terminal.

Which keyword is used to define a function in Python?

  • def
  • define
  • func
  • function
In Python, the keyword 'def' is used to define a function. For example, 'def my_function():' defines a function named 'my_function.'

Which logical operator is used in Python to combine conditional statements and returns True only if one of the conditions is True?

  • and
  • not
  • or
  • xor
The 'or' logical operator in Python is used to combine conditional statements. It returns 'True' if at least one of the conditions is 'True.'

What is the result of the expression type((1,))?

  • int
  • list
  • str
  • tuple
The expression type((1,)) will result in tuple. Even though it has one element, it's still considered a tuple due to the comma after the element.

Why would you want to create a package in Python instead of a single module?

  • To avoid using external libraries
  • To make the code run faster
  • To reduce memory consumption
  • To simplify code organization and reuse
Creating a package in Python is beneficial for code organization and reuse. It allows you to group related modules together, making it easier to manage and maintain your codebase. Packages also support namespaces, which help prevent naming conflicts.

In Python, what term is used when a function is defined inside another function?

  • Inner Function
  • Nested Function
  • Nested Method
  • Subfunction
When a function is defined inside another function, it's called a "nested function." These are also known as inner functions.

In Python, which of the following is an immutable data type?

  • Dictionary
  • List
  • Set
  • Tuple
The correct option is 4. Tuples are immutable in Python, meaning their elements cannot be changed after they are created.

What is the primary difference between the methods append() and extend() when applied to a list?

  • append() adds one item
  • append() extends lists
  • extend() adds elements
  • extend() appends lists
The primary difference between append() and extend() is that append() adds a single item to the end of a list, while extend() adds the elements of an iterable (e.g., another list) to the end of the list. This means extend() is used to combine two lists, while append() adds an element as it is, even if it's a list itself.