SlideShare uma empresa Scribd logo
1 de 29
Mohammad Hassan
Operators
• Operators
• Arithmetic operators
• Including mod and integer division
• Expression
• Priorities of operators
• Bindings of operators
• Variables
• Rules for naming
• Different types
• How to use them
• Printing output to the screen
• Getting input from the user
• Assignment operators
• Comparison operators
• Boolean operators
Objectives
Python Basic Operators
An operator is a symbol of the programming language, which
is able to operate on the values.
Operators are the constructs which can manipulate and
evaluate our data.
Consider the expression:
num = 4 + 5
operator
Types of Operators in Python
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
Membership Operators
Bitwise Operators
Identity Operators
focus of today’s lecture
Arguments
when both arguments are integers, the result is an
integer, too;
when at least one argument is a float, the result is a
float, too.
Operators – Addition & Subtraction
the + (plus) sign is the operator which is able to add two
numbers, giving the result of the addition.
“Lowest” priority in the order of operations
Function as they normally do
Examples:
1. cash = cash - bills
2. (5 + 7) / 2
3. ( ((2 + 4) * 5) / (9 - 6) )
4. -4 + 4 = 0
5. -4. + 8 = 4.0
The subtraction operator, unary and
binary operators
The subtraction operator is obviously the - (minus) sign, although you
should note that this operator also has another meaning ‒ it can change
the sign of a number.
This is a great opportunity to present a very important distinction
between unary and binary operators.
In subtracting applications, the minus operator expects two arguments:
the left (a minuend in arithmetical terms) and right (a subtrahend).
For this reason, the subtraction operator is considered to be one of the
binary operators, just like the addition, multiplication and division
operators.
-4 – 4= - 8
4. – 8 = - 4.0
-1.1= - 1.1
Operators – Multiplication & Division
An * (asterisk) sign is a multiplication operator.
A // (slash) sign is a division operator.
The value in front of the slash is a dividend, the value behind the slash,
a divisor.
The result produced by the division operator is always a float, regardless
of whether or not the result seems to be a float at first glance: 1/2, or if it looks
like a pure integer: 2/1.
Higher priority in the order of operations
than addition and subtraction
Function as they normally do
Examples:
1. tax = subtotal * 0.06
2. area = PI * (radius * radius)
3. totalDays = hours / 24
Operators – Integer Division
Reminder: integers (or ints) are whole numbers
What do you think integer division is?
A // (double slash) sign is an integer division operator. It differs from the
standard / operator in two details:
•its result lacks the fractional part ‒ it's absent (for integers), or is always equal to zero (for
floats); this means that the results are always rounded; rounding always goes to the
lesser integer.
•it conforms to the integer vs. float rule.
•integer by integer division gives an integer result. All other cases
produce floats.
Remember division in grade school?
Integer division is
 Division done without decimals
 And the remainder is discarded
 Integer division can also be called floor division
How not to divide
As you probably know, division by zero doesn't work.
Do not try to:
•perform a division by zero;
•perform an integer division by zero;
•find a remainder of a division by zero
Examples: Integer Division
Integer division uses double slashes (//)
Examples:
1. 7 / 5 = 1.4
2. 7 // 5 = 1
3. 2 / 8 = 0.25
4. 2 // 8 = 0
5. 4 // 17 // 5 = 0
6. -6 // 4 = -2
7. 6. // -4 = -2.0
evaluate from left to right
Operators – Mod
Also called “Remainder” or “modulo” or “modulus”
 Its graphical representation in Python is the % (percent) sign, which may look a bit
confusing.
Example: 17 % 5 = 2
 What do you think mod does?
 The result of the operator is a remainder left after the
integer division.
Remember division in grade school?
Modulo gives you the remainder
 The “opposite” of integer division
Examples: Mod
Mod uses the percent sign (%)
Examples:
1. 7 % 5 = 2
2. 5 % 9 = 5
3. 16 % 6 = 4
4. 23 % 4 = 3
5. 48692451673 % 2 = 1
6. 12 % 4.5 = 3.0
Modulo Answers
Result of a modulo operation will always be:
 Positive
 No less than 0
 No more than the divisor minus 1
Examples:
1. 8 % 3 =
2. 21 % 3 =
3. 13 % 3 =
2
0
1 no less than zero
no more than
the divisor minus
1
Operators – Exponentiation
“Exponentiation” is just another word for raising one
number to the power of another
Examples:
1. binary8 = 2 ** 8
2. squareArea = length ** 2
3. cubeVolume = length ** 3
4. squareRoot = num ** 0.5
Exponentiation
We've surrounded the double asterisks with spaces in our
examples. It's not compulsory, but it improves
the readability of the code.
2 ** 3 = 8
2 ** 3. = 8.0
2. ** 3 = 8.0
2. ** 3. = 8.0
Floating Point Errors
Division: Floats and Integers
Floats (decimals) and integers (whole numbers) behave in
two different ways in Python
 And in many other programming languages
Biggest difference is how their division works
 Python 3 automatically performs decimal division
 For both integers and floats
 Have to explicitly call integer division
Division Examples
What do the following expressions evaluate to?
1. 4 / 3
2. 4 // 3
3. 8 / 3
4. 8. / 2
5. 5 / 7
6. 5 // 7
= 1.3333333333333333
= 1
= 2.6666666666666667
= 4.0
= 0.7142857142857143
= 0
Rounding Errors
Sometimes we need to approximate the representation
of numbers
 0.66666666666666666666666667…
 3.14159265358979323846264338328…
We know that this can lead to incorrect
answers when doing calculations later
 Something similar happens when numbers
are stored in a computer’s memory
Float Arithmetic Examples
What do the following expressions evaluate to?
1. 8 / 3
2. 5 / 7
3. 1.99 + 0.12
4. 0.99 + 0.12
5. 1.13 * 1.19
= 2.6666666666666667
= 0.7142857142857143
= 2.11
= 1.1099999999999999
= 1.3446999999999998
Because computers store
numbers differently, they
sometimes run into different sets
of rounding errors
What’s
going on
here???
Handling Floating Point Errors
How to fix floating point errors?
You can’t!
¯_(ツ)_/¯
 They’re present in every single programming language
that uses the float data type
Just be aware that the problem exists
 Don’t rely on having exact numerical representations
when using floats in Python
Expression
Data and operators when connected together
form expressions. The simplest expression is a literal
itself.
Operators and their priorities
We've treated each operator as if it had no connection with
the others. Obviously, such an ideal and simple situation is a
rarity in real programming.
you will very often find more than one operator in one
expression, and then things are no longer so simple.
The order of their appearance is not accidental.
The phenomenon that causes some operators to act before
others is known as the hierarchy of priorities.
Python precisely defines the priorities of all operators, and
assumes that operators of a higher priority perform their
operations before the operators of a lower priority.
Arithmetic Operators in Python
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
// Integer division
% Modulo (remainder)
** Exponentiation
Order of Operations (Arithmetic)
Expressions are evaluated in what direction?
What can change this ordering?
 Parentheses!
from left to right
Operator(s) Priority
highest
lowest
**
* / // %
+ -
Operators and parentheses
you're always allowed to use parentheses, which can
change the natural order of a calculation.
In accordance with the arithmetic
rules, subexpressions in parentheses are always
calculated first.
You can use as many parentheses as you need, and
they're often used to improve the readability of an
expression, even if they don't change the order of the
operations.
An example of an expression with multiple parentheses
is here:
10.0
print((5 * ((25 % 13) + 100) / (2 * 13)) // 2)
Operators and their bindings
The binding of the operator determines the order of
computations performed by some operators with equal
priority, put side by side in one expression.
Most of Python's operators have left-sided binding,
which means that the calculation of the expression is
conducted from left to right.
(9 % 6 % 2) =1
There are two possible ways of evaluating this
expression:
• from left to right: first 9 % 6 gives 3, and then 3 %
2 gives 1;
• from right to left: first 6 % 2 gives 0, and then 9 %
0 causes a fatal error.
Operators and their bindings
But there's one interesting exception.
Use this snippet of code:
print(2 ** 2 ** 3) -> 256
The two possible results are:
•2 ** 2 → 4; 4 ** 3 → 64
•2 ** 3 → 8; 2 ** 8 → 256
•The result clearly shows that the exponentiation operator uses right-
sided binding.
print(-3 ** 2) -> -9
print(-2 ** 3) -> -8
print(-(3 ** 2)) -> 9

Mais conteúdo relacionado

Semelhante a Lecture 05.pptx

Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
bajiajugal
 
Chapter 3.3
Chapter 3.3Chapter 3.3
Chapter 3.3
sotlsoc
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
Dushmanta Nath
 

Semelhante a Lecture 05.pptx (20)

C program
C programC program
C program
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++
 
Operators
OperatorsOperators
Operators
 
Doppl development iteration #5
Doppl development   iteration #5Doppl development   iteration #5
Doppl development iteration #5
 
c_programming.pdf
c_programming.pdfc_programming.pdf
c_programming.pdf
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
Operators
OperatorsOperators
Operators
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
B.sc CSIT 2nd semester C++ Unit2
B.sc CSIT  2nd semester C++ Unit2B.sc CSIT  2nd semester C++ Unit2
B.sc CSIT 2nd semester C++ Unit2
 
Chapter 3.3
Chapter 3.3Chapter 3.3
Chapter 3.3
 
python ppt
python pptpython ppt
python ppt
 
Report on c
Report on cReport on c
Report on c
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
Operators1.pptx
Operators1.pptxOperators1.pptx
Operators1.pptx
 
03 Operators and expressions
03 Operators and expressions03 Operators and expressions
03 Operators and expressions
 
1_Python Basics.pdf
1_Python Basics.pdf1_Python Basics.pdf
1_Python Basics.pdf
 
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptx
 
#Code2 create c++ for beginners
#Code2 create  c++ for beginners #Code2 create  c++ for beginners
#Code2 create c++ for beginners
 

Último

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Último (20)

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

Lecture 05.pptx

  • 2. • Operators • Arithmetic operators • Including mod and integer division • Expression • Priorities of operators • Bindings of operators • Variables • Rules for naming • Different types • How to use them • Printing output to the screen • Getting input from the user • Assignment operators • Comparison operators • Boolean operators Objectives
  • 3. Python Basic Operators An operator is a symbol of the programming language, which is able to operate on the values. Operators are the constructs which can manipulate and evaluate our data. Consider the expression: num = 4 + 5 operator
  • 4. Types of Operators in Python Arithmetic Operators Assignment Operators Comparison Operators Logical Operators Membership Operators Bitwise Operators Identity Operators focus of today’s lecture
  • 5. Arguments when both arguments are integers, the result is an integer, too; when at least one argument is a float, the result is a float, too.
  • 6. Operators – Addition & Subtraction the + (plus) sign is the operator which is able to add two numbers, giving the result of the addition. “Lowest” priority in the order of operations Function as they normally do Examples: 1. cash = cash - bills 2. (5 + 7) / 2 3. ( ((2 + 4) * 5) / (9 - 6) ) 4. -4 + 4 = 0 5. -4. + 8 = 4.0
  • 7. The subtraction operator, unary and binary operators The subtraction operator is obviously the - (minus) sign, although you should note that this operator also has another meaning ‒ it can change the sign of a number. This is a great opportunity to present a very important distinction between unary and binary operators. In subtracting applications, the minus operator expects two arguments: the left (a minuend in arithmetical terms) and right (a subtrahend). For this reason, the subtraction operator is considered to be one of the binary operators, just like the addition, multiplication and division operators. -4 – 4= - 8 4. – 8 = - 4.0 -1.1= - 1.1
  • 8. Operators – Multiplication & Division An * (asterisk) sign is a multiplication operator. A // (slash) sign is a division operator. The value in front of the slash is a dividend, the value behind the slash, a divisor. The result produced by the division operator is always a float, regardless of whether or not the result seems to be a float at first glance: 1/2, or if it looks like a pure integer: 2/1. Higher priority in the order of operations than addition and subtraction Function as they normally do Examples: 1. tax = subtotal * 0.06 2. area = PI * (radius * radius) 3. totalDays = hours / 24
  • 9. Operators – Integer Division Reminder: integers (or ints) are whole numbers What do you think integer division is? A // (double slash) sign is an integer division operator. It differs from the standard / operator in two details: •its result lacks the fractional part ‒ it's absent (for integers), or is always equal to zero (for floats); this means that the results are always rounded; rounding always goes to the lesser integer. •it conforms to the integer vs. float rule. •integer by integer division gives an integer result. All other cases produce floats. Remember division in grade school? Integer division is  Division done without decimals  And the remainder is discarded  Integer division can also be called floor division
  • 10. How not to divide As you probably know, division by zero doesn't work. Do not try to: •perform a division by zero; •perform an integer division by zero; •find a remainder of a division by zero
  • 11. Examples: Integer Division Integer division uses double slashes (//) Examples: 1. 7 / 5 = 1.4 2. 7 // 5 = 1 3. 2 / 8 = 0.25 4. 2 // 8 = 0 5. 4 // 17 // 5 = 0 6. -6 // 4 = -2 7. 6. // -4 = -2.0 evaluate from left to right
  • 12. Operators – Mod Also called “Remainder” or “modulo” or “modulus”  Its graphical representation in Python is the % (percent) sign, which may look a bit confusing. Example: 17 % 5 = 2  What do you think mod does?  The result of the operator is a remainder left after the integer division. Remember division in grade school? Modulo gives you the remainder  The “opposite” of integer division
  • 13. Examples: Mod Mod uses the percent sign (%) Examples: 1. 7 % 5 = 2 2. 5 % 9 = 5 3. 16 % 6 = 4 4. 23 % 4 = 3 5. 48692451673 % 2 = 1 6. 12 % 4.5 = 3.0
  • 14. Modulo Answers Result of a modulo operation will always be:  Positive  No less than 0  No more than the divisor minus 1 Examples: 1. 8 % 3 = 2. 21 % 3 = 3. 13 % 3 = 2 0 1 no less than zero no more than the divisor minus 1
  • 15. Operators – Exponentiation “Exponentiation” is just another word for raising one number to the power of another Examples: 1. binary8 = 2 ** 8 2. squareArea = length ** 2 3. cubeVolume = length ** 3 4. squareRoot = num ** 0.5
  • 16. Exponentiation We've surrounded the double asterisks with spaces in our examples. It's not compulsory, but it improves the readability of the code. 2 ** 3 = 8 2 ** 3. = 8.0 2. ** 3 = 8.0 2. ** 3. = 8.0
  • 18. Division: Floats and Integers Floats (decimals) and integers (whole numbers) behave in two different ways in Python  And in many other programming languages Biggest difference is how their division works  Python 3 automatically performs decimal division  For both integers and floats  Have to explicitly call integer division
  • 19. Division Examples What do the following expressions evaluate to? 1. 4 / 3 2. 4 // 3 3. 8 / 3 4. 8. / 2 5. 5 / 7 6. 5 // 7 = 1.3333333333333333 = 1 = 2.6666666666666667 = 4.0 = 0.7142857142857143 = 0
  • 20. Rounding Errors Sometimes we need to approximate the representation of numbers  0.66666666666666666666666667…  3.14159265358979323846264338328… We know that this can lead to incorrect answers when doing calculations later  Something similar happens when numbers are stored in a computer’s memory
  • 21. Float Arithmetic Examples What do the following expressions evaluate to? 1. 8 / 3 2. 5 / 7 3. 1.99 + 0.12 4. 0.99 + 0.12 5. 1.13 * 1.19 = 2.6666666666666667 = 0.7142857142857143 = 2.11 = 1.1099999999999999 = 1.3446999999999998 Because computers store numbers differently, they sometimes run into different sets of rounding errors What’s going on here???
  • 22. Handling Floating Point Errors How to fix floating point errors? You can’t! ¯_(ツ)_/¯  They’re present in every single programming language that uses the float data type Just be aware that the problem exists  Don’t rely on having exact numerical representations when using floats in Python
  • 23. Expression Data and operators when connected together form expressions. The simplest expression is a literal itself.
  • 24. Operators and their priorities We've treated each operator as if it had no connection with the others. Obviously, such an ideal and simple situation is a rarity in real programming. you will very often find more than one operator in one expression, and then things are no longer so simple. The order of their appearance is not accidental. The phenomenon that causes some operators to act before others is known as the hierarchy of priorities. Python precisely defines the priorities of all operators, and assumes that operators of a higher priority perform their operations before the operators of a lower priority.
  • 25. Arithmetic Operators in Python Operator Meaning + Addition - Subtraction * Multiplication / Division // Integer division % Modulo (remainder) ** Exponentiation
  • 26. Order of Operations (Arithmetic) Expressions are evaluated in what direction? What can change this ordering?  Parentheses! from left to right Operator(s) Priority highest lowest ** * / // % + -
  • 27. Operators and parentheses you're always allowed to use parentheses, which can change the natural order of a calculation. In accordance with the arithmetic rules, subexpressions in parentheses are always calculated first. You can use as many parentheses as you need, and they're often used to improve the readability of an expression, even if they don't change the order of the operations. An example of an expression with multiple parentheses is here: 10.0 print((5 * ((25 % 13) + 100) / (2 * 13)) // 2)
  • 28. Operators and their bindings The binding of the operator determines the order of computations performed by some operators with equal priority, put side by side in one expression. Most of Python's operators have left-sided binding, which means that the calculation of the expression is conducted from left to right. (9 % 6 % 2) =1 There are two possible ways of evaluating this expression: • from left to right: first 9 % 6 gives 3, and then 3 % 2 gives 1; • from right to left: first 6 % 2 gives 0, and then 9 % 0 causes a fatal error.
  • 29. Operators and their bindings But there's one interesting exception. Use this snippet of code: print(2 ** 2 ** 3) -> 256 The two possible results are: •2 ** 2 → 4; 4 ** 3 → 64 •2 ** 3 → 8; 2 ** 8 → 256 •The result clearly shows that the exponentiation operator uses right- sided binding. print(-3 ** 2) -> -9 print(-2 ** 3) -> -8 print(-(3 ** 2)) -> 9

Notas do Editor

  1. Instructions To create em dash above headline Same size and weight as the headline and set using a soft return. PC: Em dash (—): Alt+Ctrl+ - (minus) Mac: Em dash (—): Shift+Alt/Option+hyphen