Python Programming Language

nakayiza shamim
4 min readFeb 22, 2019

--

Python is a programming language. Python can be used on a server to create web applications. It was created in 1991 by Guido van Rossum.

It is used for: web development (server-side), software development, mathematics and system scripting.

Python is both object-oriented and structured. Therefore it does not restrict one from the way one wants to develop his or her system.

Python can be used on a server to create web applications, It can be used alongside software to create workflows, It can connect to database systems, It can also read and modify files, it can be used to handle big data and perform complex mathematics, it can be used for rapid prototyping, or for production-ready software development.

This week I learnt about classes and objects and how to test my code. OOP is an object-oriented programming language which enables us to model real-world things and situations by use of a class. A class is a blueprint of an object and an object is an instance of a class. I learnt how to define a class in python. This is done starting with the class keyword, followed by the class name. The class name must begin with a capital letter. for example: consider the figure below.

python class code.

Description of the above code.

line(1): Any statement that starts with the #(hash) symbol is a comment about what the developer is coding. its what we read through to understand code.

line(2): we define a class called Person. By convention, class names in python begin with a capital letter. The parentheses in the class definition are empty because we’re creating this class from scratch. we terminate classes using a colon(:)

line(4): This has the __init_() method. In classes, a function is referred to as a method. The difference between a function and a method is in the way they are called. The __init_() method is a special method Python runs automatically whenever we create a new instance based on the Person class. This method has two leading and two trailing underscores, a convention that prevents the __init__ method from conflicting with other class methods. We define the __init__() method to have three parameters: self, name, and age. The self parameter is required in the method definition, and it must come first before the other parameters.

Every method call associated with a class automatically passes self, which is a reference to the instance itself. It gives the individual instance access to the attributes and methods in the class. when we make an instance of Person, we do not need to pass self as an argument because it is automatically passed.

line(5 & 6): The two variables defined at these two lines, each has the prefix self. Any variable prefixed with self is available to every method in the class, and we’ll also be able to access these variables through any instance created from the class. self.name = name takes the value stored in the parameter name and stores it in the variable name, which is then attached to the instance being created. The same process happens with self.age = age. Variables that are accessible though instances like this are called attributes.

line(8 & 11): These lines have the methods of the class. These methods begin with the key word def. They have a parameter self which enables them access the class attributes.

line(14): On this line, we are instantiating a class which means creating an object from the class.

line(16): Here we are calling a method using the dot notation. To call a method, give the name of the instance (in this case, my_sister) and the method you want to call, separated by a dot.

The output after calling the above method is as shown below.

output

A few things that stand out for me in python are:

The list comprehension that enables one to accomplish a task by writing only one line of code. This is so professional because best coders are judged according to the lines of code that accomplish a task. for example:

squares = [value**2 for value in range(1,20)]

print(squares)

Another thing that stands out for me is where we do not declare variables. Python variables are automatically declared.

Reference:

Python Crash Course. Copyright © 2016 by Eric Matthes.

--

--