From 56258dfb72c17192d1963d56da6aaf12624b3e43 Mon Sep 17 00:00:00 2001 From: Joseph G Date: Thu, 11 Oct 2018 14:10:16 -0700 Subject: Add f-string clarification. --- python3.html.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'python3.html.markdown') diff --git a/python3.html.markdown b/python3.html.markdown index b378a8c6..7683bc60 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -139,9 +139,11 @@ len("This is a string") # => 16 # still use the old style of formatting: "%s can be %s the %s way" % ("Strings", "interpolated", "old") # => "Strings can be interpolated the old way" -# You can also format using f-strings or formatted string literals +# You can also format using f-strings or formatted string literals (in Python 3.6+) name = "Reiko" f"She said her name is {name}." # => "She said her name is Reiko" +# You can basically put any Python statement inside the braces and it will be output in the string. +f"{name} is {len(name)} characters long." # None is an object -- cgit v1.2.3 From 30cdf4b25327e01c751db384e42692fd95178db1 Mon Sep 17 00:00:00 2001 From: Divay Prakash Date: Fri, 26 Oct 2018 02:35:15 +0530 Subject: Fix tuple unpacking example in python3, closes #3130 (#3328) --- python3.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'python3.html.markdown') diff --git a/python3.html.markdown b/python3.html.markdown index 7683bc60..c7fbf342 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -281,7 +281,8 @@ a, b, c = (1, 2, 3) # a is now 1, b is now 2 and c is now 3 # You can also do extended unpacking a, *b, c = (1, 2, 3, 4) # a is now 1, b is now [2, 3] and c is now 4 # Tuples are created by default if you leave out the parentheses -d, e, f = 4, 5, 6 +d, e, f = 4, 5, 6 # tuple 4, 5, 6 is unpacked into variables d, e and f +# respectively such that d = 4, e = 5 and f = 6 # Now look how easy it is to swap two values e, d = d, e # d is now 5 and e is now 4 -- cgit v1.2.3 From 4a891817ee54fb66cdf793990350f2370c70728d Mon Sep 17 00:00:00 2001 From: Niels Bom Date: Fri, 30 Nov 2018 11:52:37 +0100 Subject: [python3/en] show chaining operators nicer --- python3.html.markdown | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'python3.html.markdown') diff --git a/python3.html.markdown b/python3.html.markdown index c7fbf342..ff527716 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -96,7 +96,10 @@ False or True # => True 2 <= 2 # => True 2 >= 2 # => True -# Comparisons can be chained! +# Seeing whether a value is in a range +1 < 2 and 2 < 3 # => True +2 < 3 and 3 < 2 # => False +# Chaining makes this look nicer 1 < 2 < 3 # => True 2 < 3 < 2 # => False -- cgit v1.2.3 From 609abd33284284a487f1ac3bd0a6898ed6a77267 Mon Sep 17 00:00:00 2001 From: Niels Bom Date: Sat, 1 Dec 2018 05:29:58 +0100 Subject: [python3/en] show that True and False are ints (#3412) * [python3/en] show that True and False are ints * [python3/en] rework some boolean stuff I removed the example `-5 != False != True #=> True` because we didn't cover chaining yet. --- python3.html.markdown | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'python3.html.markdown') diff --git a/python3.html.markdown b/python3.html.markdown index c7fbf342..b3f89372 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -72,15 +72,24 @@ not False # => True True and False # => False False or True # => True -# Note using Bool operators with ints -# False is 0 and True is 1 +# True and False are actually 1 and 0 but with different keywords +True + True # => 2 +True * 8 # => 8 +False - 5 # => -5 + +# Comparison operators look at the numerical value of True and False +0 == False # => True +1 == True # => True +2 == True # => False +-5 != False # => True + +# Using boolean logical operators on ints casts them to booleans for evaluation, but their non-cast value is returned # Don't mix up with bool(ints) and bitwise and/or (&,|) +bool(0) # => False +bool(4) # => True +bool(-6) # => True 0 and 2 # => 0 -5 or 0 # => -5 -0 == False # => True -2 == True # => False -1 == True # => True --5 != False != True #=> True # Equality is == 1 == 1 # => True -- cgit v1.2.3