What is the result of the operation True or False and True?
- Error
- FALSE
- TRUE
- True and False is not allowed.
The operation 'True or False and True' will result in an error because 'and' has higher precedence than 'or,' and 'and' is trying to combine a Boolean ('False') with a non-Boolean ('True').
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.
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.
You have two sets, one containing all employees who attended a training session and another with employees who completed an online assessment. You want to find out who attended the training but did not complete the assessment. Which set operation would help?
- Difference
- Intersection
- Symmetric Difference
- Union
To find employees who attended training but did not complete the assessment, you would use the "Difference" set operation. This will give you the elements that are in the first set but not in the second.
If you have import pandas as pd, what does "pd" represent?
- It is the author's initials.
- It stands for "Python Data."
- It's a common convention for aliasing pandas.
- It's a random abbreviation for the library.
When you use import pandas as pd, you are creating an alias for the pandas library. "pd" is a commonly used abbreviation for pandas in the Python community, making it easier to reference and use pandas functions and classes in your code without typing the full module name each time.
One of the potential issues with excessive nested if statements is reduced ______ of code.
- modularity
- performance
- readability
- verbosity
One of the potential issues with excessive nested 'if' statements is reduced readability of code due to increased verbosity.
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.
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.
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.
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.
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.
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.'