mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-06 14:56:54 +02:00
Merge pull request #709 from NadOby/master
example of negative integer division
This commit is contained in:
@@ -45,9 +45,11 @@ to Python 2.x. Look for another tour of Python 3 soon!
|
|||||||
2.0 # This is a float
|
2.0 # This is a float
|
||||||
11.0 / 4.0 # => 2.75 ahhh...much better
|
11.0 / 4.0 # => 2.75 ahhh...much better
|
||||||
|
|
||||||
# Truncation or Integer division
|
# Result of integer division truncated down both for positive and negative.
|
||||||
5 // 3 # => 1
|
5 // 3 # => 1
|
||||||
5.0 // 3.0 # => 1.0 # works on floats too
|
5.0 // 3.0 # => 1.0 # works on floats too
|
||||||
|
-5 // 3 # => -2
|
||||||
|
-5.0 // 3.0 # => -2.0
|
||||||
|
|
||||||
# Modulo operation
|
# Modulo operation
|
||||||
7 % 3 # => 1
|
7 % 3 # => 1
|
||||||
|
@@ -38,9 +38,11 @@ Note: This article applies to Python 3 specifically. Check out the other tutoria
|
|||||||
# Except division which returns floats by default
|
# Except division which returns floats by default
|
||||||
35 / 5 # => 7.0
|
35 / 5 # => 7.0
|
||||||
|
|
||||||
# Truncation or Integer division
|
# Result of integer division truncated down both for positive and negative.
|
||||||
5 // 3 # => 1
|
5 // 3 # => 1
|
||||||
5.0 // 3.0 # => 1.0
|
5.0 // 3.0 # => 1.0 # works on floats too
|
||||||
|
-5 // 3 # => -2
|
||||||
|
-5.0 // 3.0 # => -2.0
|
||||||
|
|
||||||
# When you use a float, results are floats
|
# When you use a float, results are floats
|
||||||
3 * 2.0 # => 6.0
|
3 * 2.0 # => 6.0
|
||||||
@@ -51,7 +53,6 @@ Note: This article applies to Python 3 specifically. Check out the other tutoria
|
|||||||
# Enforce precedence with parentheses
|
# Enforce precedence with parentheses
|
||||||
(1 + 3) * 2 # => 8
|
(1 + 3) * 2 # => 8
|
||||||
|
|
||||||
|
|
||||||
# Boolean values are primitives
|
# Boolean values are primitives
|
||||||
True
|
True
|
||||||
False
|
False
|
||||||
@@ -60,7 +61,6 @@ False
|
|||||||
not True # => False
|
not True # => False
|
||||||
not False # => True
|
not False # => True
|
||||||
|
|
||||||
|
|
||||||
# Equality is ==
|
# Equality is ==
|
||||||
1 == 1 # => True
|
1 == 1 # => True
|
||||||
2 == 1 # => False
|
2 == 1 # => False
|
||||||
@@ -79,7 +79,6 @@ not False # => True
|
|||||||
1 < 2 < 3 # => True
|
1 < 2 < 3 # => True
|
||||||
2 < 3 < 2 # => False
|
2 < 3 < 2 # => False
|
||||||
|
|
||||||
|
|
||||||
# Strings are created with " or '
|
# Strings are created with " or '
|
||||||
"This is a string."
|
"This is a string."
|
||||||
'This is also a string.'
|
'This is also a string.'
|
||||||
|
Reference in New Issue
Block a user