An understanding of programming language with Python

Andres González Franco
4 min readJan 14, 2021

By reading this article you will be able to understand what is Python and what a programming language does in general.

Maybe you have heard that Python is a famous programming language used in several applications. And that is true, not all programming languages are similar and thus, their applications differ from each other. In the case of Python it can be used for:

  • IoT(Internet of Things)
  • AI(Artificial Intelligence)
  • Backend(Web development)
  • Data Science
  • Among others

What is a programming language?

So, if we want to understand what happens within Python rules we have to know what a programming language is. Basically, a programming language is a formal language, that allows a programmer to write orders through some instructions and parameters. These instructions will handle types of data to make things work as we want.

Any modern programming language or turning completeness must allow you to handle the basic data types or primitives(included in the language) data types we need to implement any type of algorithm(set of instructions). Some of them are int(integers), str(strings), float(float numbers), etc. And some algorithm “tools” we would need are loops, conditionals, and logic operators.

Show me the python!

Alright, let’s dig into python right away. Anytime you create a new variable, function, data, or data structure it will be called an “object”. It sounds obvious, right? well, yes but there’s a reason behind that name, an object(no matter if it’s alive or not) has a characteristic and a behavior: persons, animals, a car, a printer, a door, anything that you can imagine has a characteristic, a state, and behavior. This mindset in programming is called OOP(Object-oriented Programming) and no, not all languages handle things this way or even more, not all programmers and projects work under this paradigm, why? well, it depends on the project you are working with. Most likely an e-commerce webpage could use OOP since it will handle a lot of categories and different kinds of articles we will create within. On the other hand, a simple webpage of content, let’s say your personal webpage to show your portfolio won’t need this kind of paradigm.

When we talk about an object we could refer to it as a value of a certain data type stored in memory.

in these examples we can see objects with values 5(integer), “Wednesday”(string), and students = [“Peter”, “Andrew”, “Angela”, “Mary”] (list).

In the last example, we can see the variables day_of_month, day_of_week, and students. Those are just references or labels we give to the values. In that way, we can set several variables or aliases to one single object. For example:

In this case. 5 is the same object allocated in memory, a and b are labels for that same object or value

Aliasing

When we create an alias we are assigning one variable to another, at the end both variables refer to the same object.

Containers

As you saw in the last example with [“Peter”, “Andrew”, “Angela”, “Mary” ]. Some objects contain references to other objects, these objects are called “containers” and the following are examples of containers: lists, tuples, and dictionaries. Let’s learn more about them in the following bullet “Mutable and immutable objects”.

Mutable and immutable objects

When talking about an object’s value we can categorize them by mutable and immutable. A mutable object is an object whose value can change.

  • Some of the mutable data types in Python are list, dictionary, set, byte array, and user-defined classes(or abstract data type).
  • On the other hand, some of the immutable data types are int, float, decimal, bool, string, tuple, frozen sets, bytes, complex, and range.

Type

Even if it’s mutable or immutable every object has a data type. To get a data type of an object we can use the method or function type() it will receive as an argument de data type and as a result, it will return the data type the object belongs.

Immutable objects in memory

When we reference an object with a variable it will have a memory allocation. If we decide to dereference that object, it will still exist in memory, even if no variable is using it. Let’s see the following memory scheme example.

From Get Programming by Ana Bell - https://freecontent.manning.com/mutable-and-immutable-objects/#:~:text=Most%20python%20objects%20(booleans%2C%20integers,the%20scenes%2C%20in%20computer%20memory%3F

id

Anytime we create an object in Python. It will have a unique identification. Why? because it represents the address in memory. The only objects that will have a constant id will be the integers in the range of -5 and 256. To search which id belongs to an object we can use the method id().

Passing a variable to a function as an argument

To understand how a variable works as an argument in a function it will be determined simply by its mutable or immutable nature. If it’s an immutable value(for example an int) it will be passed as a value, on the other hand, if we pass a mutable argument it could be changed then since it is passed as a reference.

I hope with this overview you can get a better understanding of how the Python language works. Let’s keep learning!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Andres González Franco
Andres González Franco

Written by Andres González Franco

Still work in progress, but I wouldn't have been the person I am today if I haven't satisfied all my curiosites

No responses yet

Write a response