The initial release in 1991, Python have soon become one of the major languages in the world of programming. In this blog, you will learn all about the history of python, why it is so popular and some basic python language.
On the “Origins of Python”, Van Rossum wrote in 1996:
…In December 1989, I was looking for a “hobby” programming project that would keep me occupied during the week around Christmas. My office … would be closed, but I had a home computer, and not much else on my hands. I decided to write an interpreter for the new scripting language I had been thinking about lately: a descendant of ABC that would appeal to Unix/C hackers. I chose Python as a working title for the project, being in a slightly irreverent mood (and a big fan of Monty Python’s Flying Circus).
Python was not popular for a long time. It was not until 2012, Python started gaining some popularity among the developer base. According to a blog by TechRepublic, The rise of popularity of python in because of the high demand for this language in Data Science and Artificial Intelligence. This was in turn fueled by the rapid increase of third-party libraries of python, that enables the programmers in a wide range of fields to switch to python.
Using Python, you can do (quite literally) anything you want. Ranging from Web Development to App Development to Data Science to Machine Learning and a ton of other things, all thanks to thousands of third-party libraries that you can include in your project. Some of these libraries include Tensorflow (used for Machine Learning and Artificial Intelligence), NumPy and SciPy (for executing mathematical equations and scientific computations), Django and Flask (for web development) and even cython (this library enables python to be compatible to C-family languages, C/C++)
With that, let us look at some basic python syntax and stuff. I’m going to call this section of the blog as Python language… A1 – A2 level… tutorial… blog… thingy…
Well, of course, the very first step for learning python is installing the Python interpreter to your system.
You can download that from the official python website
Then, install it, if you don’t know how to install an application on your computer, then the best way is to click next until the installer starts installing the interpreter.
Then you have to set the Environment variable in your operating system. You can click below links to learn how to do that:
After the setup is over, it’s time to check if you have successfully installed Python in your system. For that, open the command prompt (for Windows) or Terminal (for Mac and Linux) and type “
If everything is the same for you also, then you are good to go. If not, you can just comment below and I’ll sort out your issue.
To write code in Python or any other programming language, you need to use a text editor. If you are using windows, you can use “Notepad” but to keep some standards and uniformity, I recommend VS Code.
You can also use a platform called Google Colab, which is an online python environment where you can do experiments and heavy duty work that your macine is not capable of.
Now, open that and write the following code:
print("Hello Idiomatic Programmer!")
And save this file as hello.py and save somewhere and remember it’s path. Now, open the command prompt (Windows) or terminal (Mac or Linux) and write this command:
If you're using Colab, then just press the "Play" button next to your code.
Congratulations, you just executed your very first python code.
Now, let’s learn about declaring variables.
Variables in Python
In programming, variables are used to hold reusable data. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. Just like in math problems you probably write, "let the final answer be x" and then you solve for x in the rest of the solution.
Just like that, in programming, you use variables to store something that you will later use in the program. There are mainly 3 different types of variables:
Static Variables: Also known as constants, are those kind of variables which hold information that will not change anywhere in your program. For example: if you want to write a program to calculate the area of a circle then Pi (𝛑) will be a variable that is a constant and will not change. There is technically no concept of static variables in Python, in Python, Global Variables are treated more or less like static variables.
Global Variables: These type of variables that will be used in the entire program, this variable may or may not be updated over the course of your program, but the purpose of this variable will not change. In python, these are the variable
Local Variables: These are the variables that are used to store temporary data and can be reused and repurposed multiple times through out the program.
PI = 3.1415 # Global Variable def areaOfACircle(radius # Local Variable): return PI*(radius**2)
If you want to know what def is, read Part 2 of this series after reading this post.
You might have noticed # <— thing. This is how we write comments in python, comments are those texts in a code that is not executed by the interpreter. The interpreter ignores the comments as your crush ignores you.
There are two types of comments:
- Single line comments: These are used when we have to write short comments. This is as you have already seen is written using # followed by the comment.
- There is another type of comment called Multi-lined comments (aka Docstrings in python): These are used when you have to write a long comment such as documentation of some function. This is written by enclosing the comment inside three quotation marks (“) like in this example:
"""This is a multiline docstring.""" print("Hello, World!")
You are probably wondering, Why we use comments in coding if that is ignored by the compiler or interpreter? If yes, then that is a very nice question and you will find the answer along with 6 other tips to improve the quality of your code here, How to write Good Code
Unlike other programming languages like JAVA and C/C++, Python is a loosely-typed language. Which means that there is no definite data type for a variable, you can use a variable as a string and the same variable as an integer. Consider the following code:
x = 50 # initialized variable x with 50 y = 100 # initialized variable y with 100 print(x+y) # this prints the sum of x and y, ie, 150
What are Data Types? It's basically a way tp tell the computer what type of data that variable should store, is it a number or is it text or anything else?
Operators in python
Now, let’s talk about Operators in python. There are 7 types of Operators in Python.
1. Arithmetic operators
Arithmetic operators are used with numeric values to perform common mathematical operations, such as adding two numbers or multiplying them.
Here are the operators that come under Arithmetic operators:
2. Assignment Operators
Assignment operators are used to assigning values to variables, these are the operators that come under Assignment operators:
3. Comparison Operators
Comparison operators are used to comparing two values, these are the operators that come under Comparison operators:
4. Logical Operators
Logical operators are used to combining conditional statements, these are the operators that come under Logical operators:
5. Identity Operators
Identity operators are used to comparing the objects, not if they are equal, but if they are actually the same object, with the same memory location, these are the operators that come under Identity operators:
6. Membership Operators
Membership operators are used to test if a sequence is presented in an object, these are the operators that come under Membership operators:
7. Bitwise Operators
Bitwise operators are used to comparing (binary) numbers, these are the operators that come under Bitwise operators:
It’s not the end…
Check out Part 2 of this post to learn more advanced Python concepts.