From fa88a3f09387c8ef4d52b7c059c7dcd5a454722d Mon Sep 17 00:00:00 2001 From: Matheus Felipe <50463866+matheusfelipeog@users.noreply.github.com> Date: Sun, 6 Feb 2022 17:28:17 -0300 Subject: [PATCH 1/5] Fix int assignment in f-Strings (Python 3.6+) --- python.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python.md b/python.md index 62acb01..10cc7b7 100644 --- a/python.md +++ b/python.md @@ -156,14 +156,14 @@ message += "Part 2." >>> f"Hello, {website}" "Hello, Quickref.ME" ->>> num = 1num = 100 +>>> num = 10 >>> f'{num} + 10 = {num + 10}' '10 + 10 = 20' ``` See: [Python F-Strings](#python-f-strings-since-python) - + Python Data Types {.cols-3} --------------- From 6130d8c3e65a0c664c880eeb75bb9f7488b61efc Mon Sep 17 00:00:00 2001 From: Matheus Felipe <50463866+matheusfelipeog@users.noreply.github.com> Date: Sun, 6 Feb 2022 17:35:45 -0300 Subject: [PATCH 2/5] Fixes space between arguments in format() Method --- python.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python.md b/python.md index 10cc7b7..fbf1eeb 100644 --- a/python.md +++ b/python.md @@ -421,9 +421,9 @@ print("%s is %d years old." % (name, age)) #### format() Method ```python -txt1 = "My name is {fname}, I'm {age}".format(fname = "John", age = 36) -txt2 = "My name is {0}, I'm {1}".format("John",36) -txt3 = "My name is {}, I'm {}".format("John",36) +txt1 = "My name is {fname}, I'm {age}".format(fname="John", age=36) +txt2 = "My name is {0}, I'm {1}".format("John", 36) +txt3 = "My name is {}, I'm {}".format("John", 36) ``` ### Input From 9b952384a57df0e7942254d12887997b7227ac41 Mon Sep 17 00:00:00 2001 From: Matheus Felipe <50463866+matheusfelipeog@users.noreply.github.com> Date: Sun, 6 Feb 2022 17:41:24 -0300 Subject: [PATCH 3/5] Fix int assignment in Python F-Strings (Since Python 3.6+) --- python.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python.md b/python.md index fbf1eeb..cd1faef 100644 --- a/python.md +++ b/python.md @@ -458,7 +458,7 @@ Python F-Strings (Since Python 3.6+) {.cols-3} >>> f"Hello, {website}" "Hello, Quickref.ME" ->>> num = 1num = 100 +>>> num = 10 >>> f'{num} + 10 = {num + 10}' '10 + 10 = 20' From e2aee301781d8351e467475376bfc5c33aa2b8e3 Mon Sep 17 00:00:00 2001 From: Matheus Felipe <50463866+matheusfelipeog@users.noreply.github.com> Date: Sun, 6 Feb 2022 18:01:33 -0300 Subject: [PATCH 4/5] Fixes in With line number Fixes: - Change the variable name from "input" to "file". "input" is built-in function, this action overrides it. - Fix space between "i" variable and "line" variable in for loop --- python.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python.md b/python.md index cd1faef..8ab16bb 100644 --- a/python.md +++ b/python.md @@ -983,8 +983,8 @@ with open("myfile.txt") as file: ``` #### With line number ```python -input = open('myfile.txt', 'r') -for i,line in enumerate(input, start=1): +file = open('myfile.txt', 'r') +for i, line in enumerate(file, start=1): print("Number %s: %s" % (i, line)) ``` From 9be7c7087fd4160e1fa63718b2f07b6ececf96d4 Mon Sep 17 00:00:00 2001 From: Matheus Felipe <50463866+matheusfelipeog@users.noreply.github.com> Date: Sun, 6 Feb 2022 18:41:22 -0300 Subject: [PATCH 5/5] Fixes in Python Classes & Inheritance Fixes: - Remove docstring from the class definition. This makes no sense for the example; - Fix indentation in Constructors; - Fix indentation in Method; - Fix class name in Class Variables; - Fix examples in Class Variables. The old one did not correspond to class variables. --- python.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/python.md b/python.md index 8ab16bb..9ce7f80 100644 --- a/python.md +++ b/python.md @@ -1061,7 +1061,6 @@ Python Classes & Inheritance {.cols-3} ```python class MyNewClass: - '''This is a docstring.''' pass # Class Instantiation @@ -1075,7 +1074,7 @@ my = MyNewClass() ```python class Animal: def __init__(self, voice): - self.voice = voice + self.voice = voice cat = Animal('Meow') print(cat.voice) # => Meow @@ -1092,7 +1091,7 @@ class Dog: # Method of the class def bark(self): - print("Ham-Ham") + print("Ham-Ham") charlie = Dog() charlie.bark() # => "Ham-Ham" @@ -1103,17 +1102,16 @@ charlie.bark() # => "Ham-Ham" ### Class Variables {.row-span-2} ```python -class my_class: +class MyClass: class_variable = "A class variable!" - -x = my_class() -y = my_class() + +# => A class variable! +print(MyClass.class_variable) + +x = MyClass() # => A class variable! print(x.class_variable) - -# => A class variable! -print(y.class_variable) ```