PYTHON is a popular language which over a million people use it every day. In this article, I am going to point out 3 key features in Python. Here they are!
1. Classes
Table of Contents
Classes are one of the ways to organize functions and variables in Python. It also can be used for creating objects.
To make a class, simply
class hello:
All classes have a function called __init__(), which is always executed when the class is called. We can use a variable called ‘self’ to store variables in the class only. These variables can only be accessed by code in the class.
class hello:
def __init__(self, name):
self.name = name
def greet(self):
print("Hello, {}!".format(self.name))
In the code above, we create a class ‘hello’. In that, we create the __init__ variable. We take 1 parameter, name. This is the name of the user which will be given to us by the user. The other parameter ‘self’, is made by the class, and we can use it to store variables to be accessed in the class only.
Creating an object
myclass = hello("YourNameHere")
myclass.greet()
In the code above, we create a new object ‘myclass’. We initialize the class ‘hello’ in that object with the __init__ parameters. Then we call the greet function which is executed.
We get the output: Hello, YourNameHere!
2. 4 Different data storage structures
There are four different ways to store data in Python. These are sets, tuples, dictionaries, and lists.
#Dictionary
identity = {"name": "yourname",
"age": "yourage"
}
#Sets
identity = {"yourname", "yourage"}
#Lists
identity = ["yourname", "yourage"]
#Tuples
identity = ("yourname", "yourage")
Dictionaries are useful in labeling values.
Values cannot be changed in sets but can be added and removed. Sets also do not accept duplicate values.
Lists are easy to change values, easy to remove values, and reorganize values.
Tuples can be separated into different variables
identity = ("yourname", "yourage")
(name, age) = identity
print(name)
print(age)
The code snippet above will give this output
yourname
yourage
3. Libraries/Modules
Python has millions of modules that add features to the language. There are some key modules like NumPy, MatPlotLib, Tkinter, etc, which are used to create arrays and deal with data, plot graphs, and make a GUI respectively. These are some of the popular libraries. I have also made a few libraries, like makepyeasy to make Python easy for beginners and ml4py to allow everyone to access AI in one Python command. You can try them and see how it goes.
Conclusion
This is all for my article. Hope you learned something!
[Image Credits – Photo by Chris Ried on Unsplash]
Leave a Reply