Back to notes
How do comparison operators differ from logical operators in Python?
Press to flip
Comparison operators compare values (e.g., `==`, `!=`) while logical operators combine boolean values and conditions (`and`, `or`, `not`).
Describe the purpose of augmented assignment operators in Python.
Augmented assignment operators, like `+=` and `-=`, provide a shorter syntax for updating the value of a variable with an operation.
What are the primary differences between lists and tuples in Python?
Lists are mutable and can be modified, while tuples are immutable and cannot be changed after creation.
Mention two methods associated with tuples and briefly describe their functionality.
The `.count()` method returns the number of occurrences of a value in a tuple, and `.index()` returns the index of the first occurrence of a value.
What is the purpose of the `print()` function in Python?
The `print()` function is used to display output to the console.
Explain the difference between `int()`, `float()`, `str()`, and `bool()` functions.
`int()` converts a value to an integer, `float()` converts to a float, `str()` converts to a string, and `bool()` converts to a boolean value.
Why would you use the `input()` function in a Python program?
The `input()` function is used to prompt the user for input and read data from the console.
What is the significance of using `in` operator with strings?
The `in` operator is used to check if a substring exists within another string.
Illustrate the order of precedence for arithmetic operations in Python.
The order of precedence is similar to math: parentheses first, followed by exponents, multiplication/division, and addition/subtraction last.
How does a while loop function and when should it be used?
A while loop repeatedly executes a block of code as long as a specified condition remains true, suitable for indefinite repetition until a condition changes.
What are some common uses of Python mentioned in the lecture?
Machine learning and AI, web development using Django, and automation of repetitive tasks.
What Python method would you use to convert a string to uppercase?
You would use the `.upper()` method to convert a string to uppercase.
Explain how list indexing and slicing works in Python.
List indexing allows access to individual elements, and slicing allows creating sublists from a list using a range of indices.
Why is it important to add Python to PATH during installation on Windows?
Adding Python to PATH allows you to run Python from any command prompt without having to specify its full directory path.
What role do control flow statements like `if` statements play in Python programming?
Control flow statements like `if` allow you to execute specific blocks of code based on conditions being true or false.
Previous
Next