filmov
tv
Python If Else - w3Schools - Chapter #33 English
![preview_player](https://i.ytimg.com/vi/F-0gMYhug9w/maxresdefault.jpg)
Показать описание
An "if statement" is written by using the if keyword.
Python relies on indentation (whitespace at the beginning of a line) to define scope in the code. Other programming languages often use curly-brackets for this purpose.
The elif keyword is pythons way of saying "if the previous conditions were not true, then try this condition".
The else keyword catches anything which isn't caught by the preceding conditions.
You can also have an else without the elif.
If you have only one statement to execute, you can put it on the same line as the if statement.
If you have only one statement to execute, one for if, and one for else, you can put it all on the same line. This technique is known as Ternary Operators, or Conditional Expressions.
The and keyword is a logical operator, and is used to combine conditional statements.
The or keyword is a logical operator, and is used to combine conditional statements.
You can have if statements inside if statements, this is called nested if statements.
if statements cannot be empty, but if you for some reason have an if statement with no content, put in the pass statement to avoid getting an error.
Python relies on indentation (whitespace at the beginning of a line) to define scope in the code. Other programming languages often use curly-brackets for this purpose.
The elif keyword is pythons way of saying "if the previous conditions were not true, then try this condition".
The else keyword catches anything which isn't caught by the preceding conditions.
You can also have an else without the elif.
If you have only one statement to execute, you can put it on the same line as the if statement.
If you have only one statement to execute, one for if, and one for else, you can put it all on the same line. This technique is known as Ternary Operators, or Conditional Expressions.
The and keyword is a logical operator, and is used to combine conditional statements.
The or keyword is a logical operator, and is used to combine conditional statements.
You can have if statements inside if statements, this is called nested if statements.
if statements cannot be empty, but if you for some reason have an if statement with no content, put in the pass statement to avoid getting an error.