Blocks are used to contain code for many purposes. In Python, blocks are indicated with indention. Blocks do not define scope in Python.
- [Instructor] Python differs from many languages in how…blocks are delimited.…Python does not use brackets or any special characters…for blocks, instead it uses indentation.…Here in Komodo I've opened a working copy of blocks.py…from chapter two of the exercise files.…And you'll notice that down here on line seven,…we have a conditional statement,…if x is less than y,…and indented below that is this print statement.…So that indent means that it's a block and it's…associated with the control above it,…in this case the if statement.…
And so if I save and run this, you'll see that we get…that result from the print and if I put another print…down here,…and save and run, you see we get both of them.…But if the condition is not true,…if I change that condition to if x is greater than y,…and save and run,…you see now we only get the something else.…And I can put several other lines of code in here.…
And save and run and none of those are printed unless…the condition is found to be true.…And if I save and run, now we get all of that.…
- 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 Efficientlywith 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.