From 3386171160dd7fc3e4e6e9aaf2d5abfebdb38d6f Mon Sep 17 00:00:00 2001 From: Aswin Sanakan Date: Tue, 5 Dec 2017 12:24:43 +0530 Subject: Fix omitting in list and clarified comments --- python3.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'python3.html.markdown') diff --git a/python3.html.markdown b/python3.html.markdown index 37987582..153384de 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -209,9 +209,9 @@ li[4] # Raises an IndexError # The start index is included, the end index is not # (It's a closed/open range for you mathy types.) li[1:3] # => [2, 4] -# Omit the end +# Omit the beginning and return the list li[2:] # => [4, 3] -# Omit the beginning +# Omit the end and return the list li[:3] # => [1, 2, 4] # Select every second entry li[::2] # =>[1, 4] -- cgit v1.2.3 From 213019c689323af7f5c531fb156c34abe8771960 Mon Sep 17 00:00:00 2001 From: Rommel Martinez Date: Sat, 3 Feb 2018 18:08:24 +0800 Subject: [python3/en]: fix typo --- python3.html.markdown | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'python3.html.markdown') diff --git a/python3.html.markdown b/python3.html.markdown index 37987582..864228e4 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -6,6 +6,7 @@ contributors: - ["Andre Polykanine", "https://github.com/Oire"] - ["Zachary Ferguson", "http://github.com/zfergus2"] - ["evuez", "http://github.com/evuez"] + - ["Rommel Martinez", "https://ebzzry.io"] filename: learnpython3.py --- @@ -546,9 +547,9 @@ all_the_args(1, 2, a=3, b=4) prints: # Use * to expand tuples and use ** to expand kwargs. args = (1, 2, 3, 4) kwargs = {"a": 3, "b": 4} -all_the_args(*args) # equivalent to foo(1, 2, 3, 4) -all_the_args(**kwargs) # equivalent to foo(a=3, b=4) -all_the_args(*args, **kwargs) # equivalent to foo(1, 2, 3, 4, a=3, b=4) +all_the_args(*args) # equivalent to all_the_args(1, 2, 3, 4) +all_the_args(**kwargs) # equivalent to all_the_args(a=3, b=4) +all_the_args(*args, **kwargs) # equivalent to all_the_args(1, 2, 3, 4, a=3, b=4) # Returning multiple values (with tuple assignments) def swap(x, y): -- cgit v1.2.3 From 50f93a94d4337b5a4f268d0832bf0fea55f55c37 Mon Sep 17 00:00:00 2001 From: qzhangjhu Date: Wed, 28 Feb 2018 10:08:29 -0500 Subject: Corrections on Python3 page --- python3.html.markdown | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'python3.html.markdown') diff --git a/python3.html.markdown b/python3.html.markdown index b0f04a02..019934cb 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -790,11 +790,11 @@ class Superhero(Human): # This calls the parent class constructor: super().__init__(name) - # overload the sing method + # override the sing method def sing(self): return 'Dun, dun, DUN!' - # add an additional class method + # add an additional instance method def boast(self): for power in self.superpowers: print("I wield the power of {pow}!".format(pow=power)) @@ -817,7 +817,7 @@ if __name__ == '__main__': # Calls parent method but uses its own class attribute print(sup.get_species()) # => Superhuman - # Calls overloaded method + # Calls overridden method print(sup.sing()) # => Dun, dun, DUN! # Calls method from Human @@ -872,7 +872,7 @@ class Batman(Superhero, Bat): def __init__(self, *args, **kwargs): # Typically to inherit attributes you have to call super: - #super(Batman, self).__init__(*args, **kwargs) + # super(Batman, self).__init__(*args, **kwargs) # However we are dealing with multiple inheritance here, and super() # only works with the next base class in the MRO list. # So instead we explicitly call __init__ for all ancestors. @@ -901,7 +901,7 @@ if __name__ == '__main__': # Calls parent method but uses its own class attribute print(sup.get_species()) # => Superhuman - # Calls overloaded method + # Calls overridden method print(sup.sing()) # => nan nan nan nan nan batman! # Calls method from Human, because inheritance order matters -- cgit v1.2.3 From b6aed7a0b38bf189922dbc47ed802de3c9769b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=90=86=E7=B5=B5=E5=AD=90?= <41843094+lowlevelware@users.noreply.github.com> Date: Sun, 29 Jul 2018 11:53:33 +0900 Subject: added example for f-string Literal string interpolation is new in python 3.6 [pep-0498](https://www.python.org/dev/peps/pep-0498/) --- python3.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'python3.html.markdown') diff --git a/python3.html.markdown b/python3.html.markdown index 019934cb..d6cfbf59 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -138,6 +138,10 @@ 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 +name = "Reiko" +f"She said her name is {name}." # => "She said her name is Reiko" + # None is an object None # => None -- cgit v1.2.3 From 04de3a348ab825f3b34eb38d07dcb3cdfc6feb7a Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Diaz Date: Tue, 7 Aug 2018 11:01:04 +0200 Subject: Clarification about sets I indicate that a set doesn't contain duplicate elements and add a little example --- python3.html.markdown | 3 +++ 1 file changed, 3 insertions(+) (limited to 'python3.html.markdown') diff --git a/python3.html.markdown b/python3.html.markdown index d6cfbf59..b378a8c6 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -7,6 +7,7 @@ contributors: - ["Zachary Ferguson", "http://github.com/zfergus2"] - ["evuez", "http://github.com/evuez"] - ["Rommel Martinez", "https://ebzzry.io"] + - ["Roberto Fernandez Diaz", "https://github.com/robertofd1995"] filename: learnpython3.py --- @@ -352,6 +353,8 @@ valid_set = {(1,), 1} # Add one more item to the set filled_set = some_set filled_set.add(5) # filled_set is now {1, 2, 3, 4, 5} +# Sets do not have duplicate elements +filled_set.add(5) # it remains as before {1, 2, 3, 4, 5} # Do set intersection with & other_set = {3, 4, 5, 6} -- cgit v1.2.3 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