Conditional statements are used to provide alternate paths for code. Python conditional statements include if, else, and elif. The syntax is simple and familiar.
- [Instructor] Conditional statements in Python…work in familiar ways.…Here in Komodo I've opened a copy of blocks.py…from chapter two of the exercise files.…Again here on line seven you see a conditional statement.…It has the keyword if…and it has the condition X is less than Y.…If the condition evaluates to true,…this print statement will print…and we have that colon there…to indicate the end of the condition.…The print statement…is indented under the conditional statement…so that it is an associated block…and if I save and run this you see we get the result,…the print statement is printed.…
Now there is a variant here…which is not often used in Python but it is available.…To put the print statement…on the same line as the condition after the colon.…In this case you don't get a block,…you only get one line of code.…In many cases that's fine…and of course you save and run this…you get exactly the same result.…In practice it's frowned upon…to put it on the same line as it is in many languages.…Even though it works…
- Python anatomy
- Types and values
- Conditionals and operators
- Building loops
- Defining functions
- Python data structures: lists, tuples, sets, and more
- Creating classes
- Handling exceptions
- Working with strings
- File input/output (I/O)
- Creating modules
- Integrating a database with Python db-api
Skill Level Intermediate
Python: Programming Efficiently (2017)with Michele Vallisneri2h 15m Intermediate
2. Language Overview
3. Types and Values
8. Structured Data
11. String Objects
12. File I/O
13. Built-in Functions
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.