1/38
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is a conditional statement?
A statement that allows decisions in code based on conditions.
Syntax of an if
statement
A way to execute code only when a condition is true.
Relational operators
Symbols used to compare values, like greater than or equal to.
Difference between assignment and equality testing
Assignment sets a value; equality checks if values are the same.
Example: Check if a number is odd
Test if the remainder when divided by 2 is not zero.
How to compare strings
Use equality or inequality operators to check if strings are the same or different.
What is lexicographical order?
String comparison based on alphabetical or ASCII order.
Operations for testing substrings
Check if a substring exists within a string using logical operators.
What is a nested branch?
A conditional statement placed inside another conditional statement.
Syntax of elif
Used to check additional conditions after the first condition is false.
What is a match/case statement?
A way to handle multiple cases in a cleaner format introduced in Python 3.10.
Boolean operators
Logical operators like and, or, and not used to combine conditions.
Use of and
Both conditions must be true for the result to be true.
Use of or
At least one of the conditions must be true for the result to be true.
Use of not
Inverts the truth value of a condition.
Check if two floats have the same sign
Test if both numbers are either positive or negative.
Input validation for age
Ensure the age is within a specific range before proceeding.
What to do in nested branching?
Test specific conditions first, then general conditions.
Common mistake in multiple conditions
Forgetting to use elif, leading to unnecessary checks.
Purpose of relational operators
To compare two values and return a true or false result.
Difference between greater than and greater than or equal
One includes equality, while the other excludes it.
Purpose of lexicographical order
To compare strings in a way similar to dictionary order.
How to test if a string ends with a specific substring
Use substring testing to check for a specific ending.
Difference between uppercase and lowercase in comparison
Uppercase letters are evaluated as smaller than lowercase.
Purpose of nested branches
To handle complex decision trees by embedding conditions.
Alternative to nested branches
Use elif to simplify and flatten the decision structure.
Example of a special case in conditions
Handle exceptions or outliers before general cases.
Key advantage of match/case
More readable and structured for multiple conditions.
What happens if no match in a case statement?
The default action is taken if defined.
Difference between and and or
And requires all conditions to be true, or requires at least one true.
Purpose of not
To reverse or negate the condition being checked.
Example of a boolean variable
A variable that holds either true or false.
When to use range checking
To verify if a value falls between two limits.
How to simplify logic with not
Use not to reduce the complexity of multiple checks.
What is equality testing for strings?
Checking if two strings have identical content.
Example of a multiway branching
Using multiple elif statements to test various conditions.
Key to writing efficient branching
Place the most likely conditions first to minimize checks.
Testing for case sensitivity
Ensure comparisons account for the exact casing of strings.
Common mistake in boolean logic
Confusing and with or, leading to incorrect result