Sunday, August 25, 2019

Python Tutorial 1 | Introduction

This is the first of Python Tutorials for Beginners. Let us learn about the Python programming language, how to download and install Python, using the Python interpreter, variables in Python and how to write a program in Python and run it. Please view my Python video tutorial 1 or read on...

Python is an open source programming language. It is easy to use. In many cases, Python needs fewer lines of code than other programming languages to accomplish the same task. Python is understandable because it uses English keywords. Python is an interpreted programming language. This means that there is no need to compile a Python program before running it.

Let us see how to download and install Python. You can get Python 3 from the Python official website. I have shown the steps in the Python Setup in my Python 1 tutorial video.
Next, you should add the path to the Path system variable. This ensures that you can run Python from any drive or any folder on your computer.
You can launch Python from the Python IDLE, which is the interactive Python interpreter. For this, click Start > All Programs > Python 3.x > IDLE. Alternately, you can launch Python from the command prompt. Either way, you should get the Python prompt, which is >>>

Next, you can type Python functions in the Python interpreter. Note that comments begin with # in Python.
>>> help(print) #see the documentation of any Python command
>>> quit()         #quit the Python interpreter

You can create variables in Python to store your data. A variable is a name or reference to your data. Now, Python is a case-sensitive programming language. This means that  v and V are two different variable names. You can continue with Python commands. You can view the Python video tutorial 1 to see such commands in action.
>>> 10 + 20    #this statement computes the expression and displays it 
>>> i = 1         #i is a variable. It is assigned the value 1.
>>> i               #this statement prints the value of i
>>>I                #NameError because variable I is not defined (Python is case-sensitive)
>>>type(i)      #this statement displays the type of data in the variable
>>>i + 5         #this statement computes the expression with the value of i and displays the expression value
>>>del i         #this statement deletes the variable

Next, let us see a small Python program based on the programming logic shown in the following flowchart:

>>> x = 1
>>> y = 2
>>> z = x + y
>>> print(z)

You can type in this Python code directly in the Python interpreter or save it in a Python file (Python scripts have .py file extension). You can see these details in my Python video tutorial 1. Thank you.