Operator precedence is the order that operators are evaluated in a compound expression. This lesson describes the precedence of Python operators.
- [Bill] Operator precedence describes the order…in which operators are evaluated in a compound expression.…For example, here's a simple expression,…two plus four times five.…Do you apply the multiplication first, or the addition?…If you multiply four times five and then add the two,…you get one result.…So four times five is 20 plus two is 22.…But if you add the two plus four first,…two plus four is six times five is 30,…you get an entirely different result.…
This is why operator precedence is important.…If you remember your high school math,…then you know to do the multiplication first,…and get the correct result.…In Python, operators have precedence.…This is a chart of operator precedence in Python.…The higher precedence operators are at the top,…and the lower precedence are at the bottom.…In many cases,…the order of these operators is obvious…and follows the same rules as the math we learned in school.…In other cases, they may not be so obvious.…
So it's always a good idea to use parentheses…to explicitly specify the order…
- 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.