Μαθαίνοντας Python: Από το μηδέν στον ήρωα
Πρώτα απ 'όλα, τι είναι η Python; Σύμφωνα με τον δημιουργό του, Guido van Rossum, ο Python είναι:
«Γλώσσα προγραμματισμού υψηλού επιπέδου και η βασική φιλοσοφία σχεδιασμού της αφορά την αναγνωσιμότητα κώδικα και μια σύνταξη που επιτρέπει στους προγραμματιστές να εκφράζουν έννοιες σε μερικές γραμμές κώδικα.»Για μένα, ο πρώτος λόγος για να μάθω τον Python ήταν ότι στην πραγματικότητα είναι ένα όμορφογλώσσα προγραμματισμού. Ήταν πραγματικά φυσικό να κωδικοποιώ και να εκφράζω τις σκέψεις μου.
Ένας άλλος λόγος ήταν ότι μπορούμε να χρησιμοποιήσουμε την κωδικοποίηση στην Python με πολλούς τρόπους: η επιστήμη των δεδομένων, η ανάπτυξη ιστού και η μηχανική εκμάθηση όλα λάμπουν εδώ. Οι Quora, Pinterest και Spotify χρησιμοποιούν όλοι την Python για την ανάπτυξη ιστοσελίδων. Ας μάθουμε λοιπόν λίγο για αυτό.
Τα βασικά
1. Μεταβλητές
Μπορείτε να σκεφτείτε τις μεταβλητές ως λέξεις που αποθηκεύουν μια τιμή. Τόσο απλό.
Στην Python, είναι πολύ εύκολο να ορίσετε μια μεταβλητή και να ορίσετε μια τιμή σε αυτήν. Φανταστείτε ότι θέλετε να αποθηκεύσετε τον αριθμό 1 σε μια μεταβλητή που ονομάζεται "μία". Ας το κάνουμε:
one = 1
Πόσο απλό ήταν αυτό; Μόλις αντιστοιχίσατε την τιμή 1 στη μεταβλητή "one".
two = 2 some_number = 10000
Και μπορείτε να αντιστοιχίσετε οποιαδήποτε άλλη τιμή σε οποιεσδήποτε άλλες μεταβλητές θέλετε. Όπως βλέπετε στον παραπάνω πίνακα, η μεταβλητή " δύο " αποθηκεύει τον ακέραιο 2 και το " some_number " αποθηκεύει 10.000 .
Εκτός από τους ακέραιους αριθμούς, μπορούμε επίσης να χρησιμοποιήσουμε booleans (True / False), string, float και πολλούς άλλους τύπους δεδομένων.
# booleans true_boolean = True false_boolean = False # string my_name = "Leandro Tk" # float book_price = 15.80
2. Ροή ελέγχου: δηλώσεις υπό όρους
Το " If " χρησιμοποιεί μια έκφραση για να αξιολογήσει εάν μια δήλωση είναι True ή False. Εάν είναι αλήθεια, εκτελεί ό, τι βρίσκεται μέσα στη δήλωση "if". Για παράδειγμα:
if True: print("Hello Python If") if 2 > 1: print("2 is greater than 1")
Το 2 είναι μεγαλύτερο από 1 , οπότε εκτελείται ο κωδικός « εκτύπωσης ».
Η δήλωση " else " θα εκτελεστεί εάν η έκφραση " if " είναι ψευδής .
if 1 > 2: print("1 is greater than 2") else: print("1 is not greater than 2")
Το 1 δεν είναι μεγαλύτερο από 2 , οπότε θα εκτελεστεί ο κώδικας μέσα στη δήλωση " else "
Μπορείτε επίσης να χρησιμοποιήσετε μια δήλωση " elif ":
if 1 > 2: print("1 is greater than 2") elif 2 > 1: print("1 is not greater than 2") else: print("1 is equal to 2")
3. Βρόχος / επανάληψη
Στην Python, μπορούμε να επαναλάβουμε σε διάφορες μορφές. Θα μιλήσω για δύο: ενώκαι για .
While Looping: ενώ η δήλωση είναι True, θα εκτελεστεί ο κώδικας μέσα στο μπλοκ. Έτσι, αυτός ο κωδικός θα εκτυπώσει τον αριθμό από 1 έως 10 .
num = 1 while num <= 10: print(num) num += 1
Το ενώ βρόχος χρειάζεται μια « κατάσταση βρόχου. Αν παραμείνει Αληθινό, συνεχίζει να επαναλαμβάνεται. Σε αυτό το παράδειγμα, πότε num
είναι 11
η κατάσταση βρόχου ίση False
.
Ένα άλλο βασικό κομμάτι κώδικα για να το κατανοήσετε καλύτερα:
loop_condition = True while loop_condition: print("Loop Condition keeps: %s" %(loop_condition)) loop_condition = False
Η κατάσταση του βρόχου είναι True
έτσι συνεχίζει - μέχρι να το ρυθμίσουμε False
.
Για Looping : εφαρμόζετε τη μεταβλητή " num " στο μπλοκ και η δήλωση " για " θα την επαναλάβει για εσάς. Αυτός ο κωδικός θα εκτυπώσει τον ίδιο με τον κωδικό ενώ : 1 έως 10 .
for i in range(1, 11): print(i)
Βλέπω? Είναι τόσο απλό. Το εύρος ξεκινά με 1
και πηγαίνει μέχρι το 11
τρίτο στοιχείο ( 10
είναι το 10
τρίτο στοιχείο).
Λίστα: Συλλογή | Σειρά | Δομή δεδομένων
Φανταστείτε ότι θέλετε να αποθηκεύσετε τον ακέραιο 1 σε μια μεταβλητή. Αλλά ίσως τώρα θέλετε να αποθηκεύσετε 2. Και 3, 4, 5…
Έχω άλλο τρόπο να αποθηκεύσω όλους τους ακέραιους αριθμούς που θέλω, αλλά όχι σε εκατομμύρια μεταβλητές ; Το μαντέψατε - υπάρχει πράγματι ένας άλλος τρόπος να τα αποθηκεύσετε.
List
είναι μια συλλογή που μπορεί να χρησιμοποιηθεί για την αποθήκευση μιας λίστας τιμών (όπως αυτοί οι ακέραιοι αριθμοί που θέλετε). Ας το χρησιμοποιήσουμε λοιπόν:
my_integers = [1, 2, 3, 4, 5]
Είναι πολύ απλό. Δημιουργήσαμε έναν πίνακα και τον αποθηκεύσαμε στο my_integer .
Αλλά ίσως ρωτάτε: "Πώς μπορώ να λάβω μια τιμή από αυτόν τον πίνακα;"
Μεγάλη ερώτηση. List
έχει μια έννοια που ονομάζεται ευρετήριο . Το πρώτο στοιχείο παίρνει το δείκτη 0 (μηδέν). Το δεύτερο παίρνει 1, και ούτω καθεξής. Παίρνετε την ιδέα.
Για να γίνει πιο ξεκάθαρο, μπορούμε να αναπαραστήσουμε τον πίνακα και κάθε στοιχείο με το ευρετήριό του. Μπορώ να το σχεδιάσω:

Χρησιμοποιώντας τη σύνταξη Python, είναι επίσης απλό να κατανοήσετε:
my_integers = [5, 7, 1, 3, 4] print(my_integers[0]) # 5 print(my_integers[1]) # 7 print(my_integers[4]) # 4
Φανταστείτε ότι δεν θέλετε να αποθηκεύσετε ακέραιους αριθμούς. Θέλετε απλώς να αποθηκεύσετε χορδές, όπως μια λίστα με τα ονόματα των συγγενών σας. Το δικό μου θα μοιάζει με αυτό:
relatives_names = [ "Toshiaki", "Juliana", "Yuji", "Bruno", "Kaio" ] print(relatives_names[4]) # Kaio
Λειτουργεί με τον ίδιο τρόπο όπως ακέραιοι. Ομορφη.
We just learned how Lists
indices work. But I still need to show you how we can add an element to the List
data structure (an item to a list).
The most common method to add a new value to a List
is append
. Let’s see how it works:
bookshelf = [] bookshelf.append("The Effective Engineer") bookshelf.append("The 4 Hour Work Week") print(bookshelf[0]) # The Effective Engineer print(bookshelf[1]) # The 4 Hour Work Week
append
is super simple. You just need to apply the element (eg. “The Effective Engineer”) as the append
parameter.
Well, enough about Lists
. Let’s talk about another data structure.
Dictionary: Key-Value Data Structure
Now we know that Lists
are indexed with integer numbers. But what if we don’t want to use integer numbers as indices? Some data structures that we can use are numeric, string, or other types of indices.
Let’s learn about the Dictionary
data structure. Dictionary
is a collection of key-value pairs. Here’s what it looks like:
dictionary_example = { "key1": "value1", "key2": "value2", "key3": "value3" }
The key is the index pointing to thevalue. How do we access the Dictionary
value? You guessed it — using the key. Let’s try it:
dictionary_tk = { "name": "Leandro", "nickname": "Tk", "nationality": "Brazilian" } print("My name is %s" %(dictionary_tk["name"])) # My name is Leandro print("But you can call me %s" %(dictionary_tk["nickname"])) # But you can call me Tk print("And by the way I'm %s" %(dictionary_tk["nationality"])) # And by the way I'm Brazilian
I created a Dictionary
about me. My name, nickname, and nationality. Those attributes are the Dictionary
keys.
As we learned how to access the List
using index, we also use indices (keys in the Dictionary
context) to access the value stored in the Dictionary
.
In the example, I printed a phrase about me using all the values stored in the Dictionary
. Pretty simple, right?
Another cool thing about Dictionary
is that we can use anything as the value. In the Dictionary
I created, I want to add the key “age” and my real integer age in it:
dictionary_tk = { "name": "Leandro", "nickname": "Tk", "nationality": "Brazilian", "age": 24 } print("My name is %s" %(dictionary_tk["name"])) # My name is Leandro print("But you can call me %s" %(dictionary_tk["nickname"])) # But you can call me Tk print("And by the way I'm %i and %s" %(dictionary_tk["age"], dictionary_tk["nationality"])) # And by the way I'm Brazilian
Here we have a key (age) value (24) pair using string as the key and integer as the value.
As we did with Lists
, let’s learn how to add elements to a Dictionary
. The keypointing to avalue is a big part of what Dictionary
is. This is also true when we are talking about adding elements to it:
dictionary_tk = { "name": "Leandro", "nickname": "Tk", "nationality": "Brazilian" } dictionary_tk['age'] = 24 print(dictionary_tk) # {'nationality': 'Brazilian', 'age': 24, 'nickname': 'Tk', 'name': 'Leandro'}
We just need to assign a value to a Dictionary
key. Nothing complicated here, right?
Iteration: Looping Through Data Structures
As we learned in the Python Basics, the List
iteration is very simple. We Python
developers commonly use For
looping. Let’s do it:
bookshelf = [ "The Effective Engineer", "The 4-hour Workweek", "Zero to One", "Lean Startup", "Hooked" ] for book in bookshelf: print(book)
So for each book in the bookshelf, we (can do everything with it) print it. Pretty simple and intuitive. That’s Python.
For a hash data structure, we can also use the for
loop, but we apply the key
:
dictionary = { "some_key": "some_value" } for key in dictionary: print("%s --> %s" %(key, dictionary[key])) # some_key --> some_value
This is an example how to use it. For each key
in the dictionary
, we print
the key
and its corresponding value
.
Another way to do it is to use the iteritems
method.
dictionary = { "some_key": "some_value" } for key, value in dictionary.items(): print("%s --> %s" %(key, value)) # some_key --> some_value
We did name the two parameters as key
and value
, but it is not necessary. We can name them anything. Let’s see it:
dictionary_tk = { "name": "Leandro", "nickname": "Tk", "nationality": "Brazilian", "age": 24 } for attribute, value in dictionary_tk.items(): print("My %s is %s" %(attribute, value)) # My name is Leandro # My nickname is Tk # My nationality is Brazilian # My age is 24
We can see we used attribute as a parameter for the Dictionary
key
, and it works properly. Great!
Classes & Objects
A little bit of theory:
Objects are a representation of real world objects like cars, dogs, or bikes. The objects share two main characteristics: data and behavior.
Cars have data, like number of wheels, number of doors, and seating capacity They also exhibit behavior: they can accelerate, stop, show how much fuel is left, and so many other things.
We identify data as attributes and behavior as methods in object-oriented programming. Again:
Data → Attributes and Behavior → Methods
And a Class is the blueprint from which individual objects are created. In the real world, we often find many objects with the same type. Like cars. All the same make and model (and all have an engine, wheels, doors, and so on). Each car was built from the same set of blueprints and has the same components.
Python Object-Oriented Programming mode: ON
Python, as an Object-Oriented programming language, has these concepts: class and object.
A class is a blueprint, a model for its objects.
So again, a class it is just a model, or a way to define attributes and behavior (as we talked about in the theory section). As an example, a vehicle class has its own attributes that define what objects are vehicles. The number of wheels, type of tank, seating capacity, and maximum velocity are all attributes of a vehicle.
With this in mind, let’s look at Python syntax for classes:
class Vehicle: pass
We define classes with a class statement — and that’s it. Easy, isn’t it?
Objects are instances of a class. We create an instance by naming the class.
car = Vehicle() print(car) #
Here car
is an object (or instance) of the classVehicle
.
Remember that our vehicle class has four attributes: number of wheels, type of tank, seating capacity, and maximum velocity. We set all these attributes when creating a vehicle object. So here, we define our class to receive data when it initiates it:
class Vehicle: def __init__(self, number_of_wheels, type_of_tank, seating_capacity, maximum_velocity): self.number_of_wheels = number_of_wheels self.type_of_tank = type_of_tank self.seating_capacity = seating_capacity self.maximum_velocity = maximum_velocity
We use the init
method. We call it a constructor method. So when we create the vehicle object, we can define these attributes. Imagine that we love the Tesla Model S, and we want to create this kind of object. It has four wheels, runs on electric energy, has space for five seats, and the maximum velocity is 250km/hour (155 mph). Let’s create this object:
tesla_model_s = Vehicle(4, 'electric', 5, 250)
Four wheels + electric “tank type” + five seats + 250km/hour maximum speed.
All attributes are set. But how can we access these attributes’ values? We send a message to the object asking about them. We call it a method. It’s the object’s behavior. Let’s implement it:
class Vehicle: def __init__(self, number_of_wheels, type_of_tank, seating_capacity, maximum_velocity): self.number_of_wheels = number_of_wheels self.type_of_tank = type_of_tank self.seating_capacity = seating_capacity self.maximum_velocity = maximum_velocity def number_of_wheels(self): return self.number_of_wheels def set_number_of_wheels(self, number): self.number_of_wheels = number
This is an implementation of two methods: number_of_wheels and set_number_of_wheels. We call it getter
& setter
. Because the first gets the attribute value, and the second sets a new value for the attribute.
In Python, we can do that using @property
(decorators
) to define getters
and setters
. Let’s see it with code:
class Vehicle: def __init__(self, number_of_wheels, type_of_tank, seating_capacity, maximum_velocity): self.number_of_wheels = number_of_wheels self.type_of_tank = type_of_tank self.seating_capacity = seating_capacity self.maximum_velocity = maximum_velocity @property def number_of_wheels(self): return self.__number_of_wheels @number_of_wheels.setter def number_of_wheels(self, number): self.__number_of_wheels = number
And we can use these methods as attributes:
tesla_model_s = Vehicle(4, 'electric', 5, 250) print(tesla_model_s.number_of_wheels) # 4 tesla_model_s.number_of_wheels = 2 # setting number of wheels to 2 print(tesla_model_s.number_of_wheels) # 2
This is slightly different than defining methods. The methods work as attributes. For example, when we set the new number of wheels, we don’t apply two as a parameter, but set the value 2 to number_of_wheels
. This is one way to write pythonic
getter
and setter
code.
But we can also use methods for other things, like the “make_noise” method. Let’s see it:
class Vehicle: def __init__(self, number_of_wheels, type_of_tank, seating_capacity, maximum_velocity): self.number_of_wheels = number_of_wheels self.type_of_tank = type_of_tank self.seating_capacity = seating_capacity self.maximum_velocity = maximum_velocity def make_noise(self): print('VRUUUUUUUM')
Όταν ονομάζουμε αυτήν τη μέθοδο, επιστρέφει απλώς μια συμβολοσειρά " VRRRRUUUUM. "
tesla_model_s = Vehicle(4, 'electric', 5, 250) tesla_model_s.make_noise() # VRUUUUUUUM
Ενθυλάκωση: Απόκρυψη πληροφοριών
Το Encapsulation είναι ένας μηχανισμός που περιορίζει την άμεση πρόσβαση στα δεδομένα και τις μεθόδους των αντικειμένων. Ταυτόχρονα, διευκολύνει τη λειτουργία αυτών των δεδομένων (μέθοδοι αντικειμένων).
«Η ενθυλάκωση μπορεί να χρησιμοποιηθεί για την απόκρυψη των μελών και της λειτουργίας μελών. Σύμφωνα με αυτόν τον ορισμό, η ενθυλάκωση σημαίνει ότι η εσωτερική αναπαράσταση ενός αντικειμένου είναι γενικά κρυμμένη από την προβολή εκτός του ορισμού του αντικειμένου. " - ΒικιπαίδειαΌλη η εσωτερική αναπαράσταση ενός αντικειμένου κρύβεται από το εξωτερικό. Μόνο το αντικείμενο μπορεί να αλληλεπιδράσει με τα εσωτερικά του δεδομένα.
Κατ 'αρχάς, πρέπει να κατανοήσουμε το πώς public
και το non-public
παράδειγμα μεταβλητές και μεθόδους εργασίας.
Μεταβλητές δημόσιας παρουσίας
For a Python class, we can initialize a public instance variable
within our constructor method. Let’s see this:
Within the constructor method:
class Person: def __init__(self, first_name): self.first_name = first_name
Here we apply the first_name
value as an argument to the public instance variable
.
tk = Person('TK') print(tk.first_name) # => TK
Within the class:
class Person: first_name = 'TK'
Here, we do not need to apply the first_name
as an argument, and all instance objects will have a class attribute
initialized with TK
.
tk = Person() print(tk.first_name) # => TK
Cool. We have now learned that we can use public instance variables
and class attributes
. Another interesting thing about the public
part is that we can manage the variable value. What do I mean by that? Our object
can manage its variable value: Get
and Set
variable values.
Keeping the Person
class in mind, we want to set another value to its first_name
variable:
tk = Person('TK') tk.first_name = 'Kaio' print(tk.first_name) # => Kaio
Ορίστε. Απλώς ορίσαμε μια άλλη τιμή ( kaio
) στη first_name
μεταβλητή παρουσίας και ενημέρωσε την τιμή. Τόσο απλό. Δεδομένου ότι είναι μια public
μεταβλητή, μπορούμε να το κάνουμε αυτό.
Μη δημόσια μεταβλητή παρουσίας
Δεν χρησιμοποιούμε τον όρο «ιδιωτικό» εδώ, καθώς κανένα χαρακτηριστικό δεν είναι πραγματικά ιδιωτικό στο Python (χωρίς μια γενικά περιττή εργασία). - PEP 8Ως public instance variable
, μπορούμε να ορίσουμε και τα non-public instance variable
δύο μέσα στη μέθοδο κατασκευαστή ή στην τάξη. Η διαφορά σύνταξης είναι: για non-public instance variables
, χρησιμοποιήστε ένα σύμβολο υπογράμμισης ( _
) πριν από το variable
όνομα.
_spam
) πρέπει να αντιμετωπίζεται ως μη δημόσιο μέρος του API (είτε πρόκειται για συνάρτηση, μέθοδο είτε για μέλος δεδομένων) " - Ίδρυμα λογισμικού Python
Ακολουθεί ένα παράδειγμα:
class Person: def __init__(self, first_name, email): self.first_name = first_name self._email = email
Είδατε τη email
μεταβλητή; Έτσι καθορίζουμε non-public variable
:
tk = Person('TK', '[email protected]') print(tk._email) # [email protected]
Μπορούμε να έχουμε πρόσβαση και να το ενημερώσουμε.
Non-public variables
είναι απλώς μια σύμβαση και πρέπει να αντιμετωπίζεται ως μη δημόσιο μέρος του API.
Χρησιμοποιούμε λοιπόν μια μέθοδο που μας επιτρέπει να το κάνουμε μέσα στον ορισμό της τάξης μας. Ας εφαρμόσουμε δύο μεθόδους ( email
και update_email
) για να το κατανοήσουμε:
class Person: def __init__(self, first_name, email): self.first_name = first_name self._email = email def update_email(self, new_email): self._email = new_email def email(self): return self._email
Τώρα μπορούμε να ενημερώσουμε και να αποκτήσουμε πρόσβαση non-public variables
χρησιμοποιώντας αυτές τις μεθόδους. Ας δούμε:
tk = Person('TK', '[email protected]') print(tk.email()) # => [email protected] # tk._email = '[email protected]' -- treat as a non-public part of the class API print(tk.email()) # => [email protected] tk.update_email('[email protected]') print(tk.email()) # => [email protected]
- We initiated a new object with
first_name
TK andemail
[email protected] - Printed the email by accessing the
non-public variable
with a method - Tried to set a new
email
out of our class - We need to treat
non-public variable
asnon-public
part of the API - Updated the
non-public variable
with our instance method - Success! We can update it inside our class with the helper method
Public Method
With public methods
, we can also use them out of our class:
class Person: def __init__(self, first_name, age): self.first_name = first_name self._age = age def show_age(self): return self._age
Let’s test it:
tk = Person('TK', 25) print(tk.show_age()) # => 25
Great — we can use it without any problem.
Non-public Method
But with non-public methods
we aren’t able to do it. Let’s implement the same Person
class, but now with a show_age
non-public method
using an underscore (_
).
class Person: def __init__(self, first_name, age): self.first_name = first_name self._age = age def _show_age(self): return self._age
And now, we’ll try to call this non-public method
with our object:
tk = Person('TK', 25) print(tk._show_age()) # => 25
Μπορούμε να έχουμε πρόσβαση και να το ενημερώσουμε.
Non-public methods
είναι απλώς μια σύμβαση και πρέπει να αντιμετωπίζεται ως μη δημόσιο μέρος του API.
Ακολουθεί ένα παράδειγμα για το πώς μπορούμε να το χρησιμοποιήσουμε:
class Person: def __init__(self, first_name, age): self.first_name = first_name self._age = age def show_age(self): return self._get_age() def _get_age(self): return self._age tk = Person('TK', 25) print(tk.show_age()) # => 25
Εδώ έχουμε ένα _get_age
non-public method
και ένα show_age
public method
. Το show_age
δοχείο μπορεί να χρησιμοποιηθεί από το αντικείμενο μας (εκτός της τάξης μας) και το _get_age
μόνο που χρησιμοποιείται στον ορισμό της κατηγορίας μας (εσωτερική show_age
μέθοδος) Και πάλι: ως θέμα σύμβασης.
Περίληψη ενθυλάκωσης
Με ενθυλάκωση μπορούμε να διασφαλίσουμε ότι η εσωτερική αναπαράσταση του αντικειμένου είναι κρυμμένη από το εξωτερικό.
Κληρονομικότητα: συμπεριφορές και χαρακτηριστικά
Ορισμένα αντικείμενα έχουν κάποια κοινά πράγματα: τη συμπεριφορά και τα χαρακτηριστικά τους.
Για παράδειγμα, κληρονόμησα ορισμένα χαρακτηριστικά και συμπεριφορές από τον πατέρα μου. Κληρονόμησα τα μάτια και τα μαλλιά του ως χαρακτηριστικά, και την ανυπομονησία και την ενδοστροφή του ως συμπεριφορές.
In object-oriented programming, classes can inherit common characteristics (data) and behavior (methods) from another class.
Let’s see another example and implement it in Python.
Imagine a car. Number of wheels, seating capacity and maximum velocity are all attributes of a car. We can say that anElectricCar class inherits these same attributes from the regular Car class.
class Car: def __init__(self, number_of_wheels, seating_capacity, maximum_velocity): self.number_of_wheels = number_of_wheels self.seating_capacity = seating_capacity self.maximum_velocity = maximum_velocity
Our Car class implemented:
my_car = Car(4, 5, 250) print(my_car.number_of_wheels) print(my_car.seating_capacity) print(my_car.maximum_velocity)
Once initiated, we can use all instance variables
created. Nice.
In Python, we apply a parent class
to the child class
as a parameter. An ElectricCar class can inherit from our Car class.
class ElectricCar(Car): def __init__(self, number_of_wheels, seating_capacity, maximum_velocity): Car.__init__(self, number_of_wheels, seating_capacity, maximum_velocity)
Simple as that. We don’t need to implement any other method, because this class already has it (inherited from Car class). Let’s prove it:
my_electric_car = ElectricCar(4, 5, 250) print(my_electric_car.number_of_wheels) # => 4 print(my_electric_car.seating_capacity) # => 5 print(my_electric_car.maximum_velocity) # => 250
Beautiful.
That’s it!
We learned a lot of things about Python basics:
- How Python variables work
- How Python conditional statements work
- How Python looping (while & for) works
- How to use Lists: Collection | Array
- Dictionary Key-Value Collection
- How we can iterate through these data structures
- Objects and Classes
- Attributes as objects’ data
- Methods as objects’ behavior
- Using Python getters and setters & property decorator
- Encapsulation: hiding information
- Inheritance: behaviors and characteristics
Congrats! You completed this dense piece of content about Python.
Αν θέλετε ένα πλήρες μάθημα Python, μάθετε περισσότερες δεξιότητες κωδικοποίησης πραγματικού κόσμου και δημιουργήστε έργα, δοκιμάστε το One Month Python Bootcamp . Τα λέμε εκεί ☺
Για περισσότερες ιστορίες και θέσεις για το ταξίδι της μάθησης μου και το mastering του προγραμματισμού, ακολουθήστε δημοσίευση μου Η Αναγέννηση Developer .
Διασκεδάστε, συνεχίστε να μαθαίνετε και συνεχίζετε να κωδικοποιείτε.
Το Twitter και το Github. ☺