Python is one of the most popular computer languages. And if you are a beginner, we have listed Python among the 5 best programming language for beginners. I must say, this is the right time for you to get started with Python.
Whether you want to write a script for automation or manipulation data for analytics or building websites; Python is one of the best choices.
Looking at the power of Python language of doing so many things, Python is widely accepted in the software industry in a wide range of projects.
Let’s see the best way to learn Python…
Note: There are two major Python versions- Python 2 and Python 3. Going forward, you should focus on Python 3 rather than Python 2.
Table of Contents
I am glad for your choice of learning Python. Myself being Python developer, I am going to give you steps to kick start learning Python.
There are two versions of Python: Python 2.x and Python 3.x. Python 3.x is released long back but many still use Python 2.x. Python 2.x is very much comfortable and stable.
The code running on Python 2 is not necessary to work on Python 3. So it is difficult to move from Python 2 to Python 3. This is the main reason as many companies (even Google) still uses Python 2 version.
For more detail, you can read the difference between Python 2 and Python 3.
As you are a beginner, I would suggest you install the latest Python 3 version.
Download the Python from its official website.
Once the download completes, install it.
c:/python38
).Start
then right click on My Computer
.Properties
. Click Advance System Setting
.Environment Variables
.System Variables
search for variable Path
. And click on edit
.Variable value
.Now, it’s time to verify Python installation and configuration.
Window:
Press Windows+R
and then type python
. Or you can open a command prompt and the execute command python
.
Linux:
Open a terminal and execute the command python
.
If the Python is installed properly, it will open a Python console. And then just test your first python code.
print("Hello, World!")
#Hello, World!
You can try some basic arithmetic calculations using python commands.
ani:~$ python Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) Type "help", "copyright", "credits" or "license" for more information. >>> 3 + 6 9 >>> 56 - 2 54 >>> 56 * 7 392 >>> 55 / 8 6 >>> 67 % 9 4 >>> >>> exit()
exit()
is a command to terminate the Python console.
This is the basic calculator you can use if you ever been into accounting bills. I prefer it to the calculator software that comes with the system. 😛
Now we are just running Python commands. Let’s see how to write and run the Python program.
To write a python program you need an editor.
Windows User:
If you are using Windows OS, you might have notepad installed on your system. Initially, you can use that. Notepad only shows basic text and doesn’t highlight syntax. But it is ok, initially.
To highlight syntax you can install Notepad++. It makes your programming easy. It is also open-source.
If you want to start building the project, I would recommend using a Sublime editor.
Later you can move to the PyCharm. It is a dedicated IDE for Python that needs to be configured before using it. I have already written a complete tutorial for PyCharm setup.
Linux User:
vim is the best editor you should use. I use it personally and I don’t want to move to any other editor. It is the standard editor for all the programming development.
Without getting much confusion; For beginners, I would recommend using Notepad++ on Windows and Vim on Linux based systems.
All the setup is ready for getting started with Python. Let’s start savoring Python skills.
Open the editor and write a hello world program.
print("Hello, World!")
You don’t need to write any functions. You don’t need to write any classes or import any classes. This is just one line program that prints the output on the console.
Isn’t it simple?
Save the file with .py
extension (says helloPro.py
).
And run the Python program from the command prompt (terminal for Linux user).
Command to compile and to run the Python Program:
python helloPro.py
It will print “Hello, World” on the command prompt/ Python console.
That’s all. You are ready with the Python.
Here are some simple programs you can try to run.
Printing value of the variable:
a = 10
print("value of a is ", a)
#value of a is 10
Find the sum of two numbers:
a = 10
b = 29
print("Sum = ", a+b)
#Sum = 39
Comment in Python:
You can use the comment in Python code. A comment is followed by the character ‘#’.
a = 10 #a is first intger variable
b = 29 #b is second integer variable
#Calculating sum of two integer
print("Sum = ", a+b)
#Sum = 39
Exploring Python further…
In the above programs, we have hardcoded the values of a and b. You can take these values as user input. Read the next Python tutorial for taking user input.
Here is a sample program for the Swapping value of two variables in Python.
For your learning, you can try running Python programs we have shared in our Python tutorial.
For being a beginner, getting started with Python is not easy like all other programming languages. And I am sure you might have many doubts. Please write in a comment. I answer your question right back.
Happy Pythoning!
Good to see CSEStack.org growing.. Thanks for Python article. It motivated me to start with Python.
Thanks, Aniket! I am glad to see here and to find it useful. Will keep posting more such Python tutorials. Stay tuned!
can anybody explain call by value and call by reference in python?
Hi anirudha.
I am linux admin and am very confused like what to do for my future..
What language or scripting i should learn ..
Kindly help.
Hi sukhpreet,
Being Linux admin, you must be good at bash scripting.
I would recommend you to learn Python. It will help you in many ways. You can use it as scripting as well as the full fledged programming language.
Python is most suitable for all the today’s growing technologies in IT industry such as ML, AL, Data science… Many of the automation scripts are written in Python. Moreover, it is easy to learn Python (at least to learn basics and to begin with…)
I AM NOT ABLE TO RUN MY FILE SAVED IN NOTEPAD++AS HELLP.PY IN THE CONSOLE. PLEASE HELP
Asmita, please check if you have opened the console in the same directory where you have saved your Python file.
I AM JUST A BEGINNER. SO WILL U PLEASE TELL IN MORE DETAIL WHAT EXACTLY SHUD I DO?
1. If you are new to the Python programming, follow the complete Python tutorial here – https://www.csestack.org/python/
2. Try solving as many programming questions as you can. List of coding questions for practice.
3. Join our Python programming community to discuss more Python.
ACTUALLY, THE PROBLEM IS THAT I AM ABLE TO PERFORM OTHER SIMPLE COMMANDS IN CMD AND PYTHON.EXE BUT THE COMMAND PYTHON HELLOPRO.PY IS SHOWING INVALID SYNTAX IN BOTH
Hi Asmita, can you share the code or exact error you are getting while running Python code?
This helps, Many thanks to you.
You’re welcome, Ushie!
Hello!! In the second step of installing python Setting Environment Variable, I can’t find the open variable value part.
Hi Prabin, if you are using the latest Windows versions (Windows 10), after “Path > Edit” click on “New” and add the path. This will work.
Hey, I noticed you didn’t use parentheses around the print method. I thought you have to do that for python 3.
Hi Seth! Thanks for notifying us. Earlier this code was written for Python 2. Now, we have rewritten this tutorial for Python 3.