Python - Tutorials

Python Tutorials

About:

Python is a general purpose integrated interpreted, interactive, object-oriented and high level programming language. It was created by Guido van Rossum during 1985-1990.

In this tutorial you can understand the python programming language.

Why python?

If you are new to programming, python is the best language to learn and you can understand the coding concepts easily in python with normal understandable English key words.

Python is most important programming language for students and working professionals especially in web development domain.

Domain Branches of Python:

  • Object oriented programming and data structures
  • Web development
  • Data science
  • Machine learning
  • Deep learning
  • Artificial intelligence
  • Desktop application development
  • DevOps
  • Web scraping
  • Natural language processing

We will learn these Domains in upcoming blogs along with basics of python.

Advantages of learning python:

  • Open source with a good community.
  • More libraries to reduce your time on coding.
  • Versatile, Easy to Use and Fast to Develop.
  • Speed limitations.
  • Problems with Threading.
  • Object oriented programming.
  • Great for prototypes.
  • Presence of third-party modules.

Ok guys… now you all get some introduction and basic details about python.

Now we are going to learn how to code our first program in python.

Hurraayyyy……..

Hello Word Program:

Now we are going to print a “Hello word” in python.

Don’t strain yourself,

Just type the below comment in your python file which has .py extension. print(“Hello word”)

if you are running this code you will get Output in console like this.

>Hello word

Did you see how easy the python to learn. Let’s get started with this excitement. Come on python aspirants.

Python setup:

If you want to code in python, initially you have to install python in your pc and setup the environment for python.

Here, I’ll teach you how to install python and how to setup environment for python.

Let’s start.

First we have to check whether the python already installed in our pc.

To check that

  1. open your comment prompt (terminal window)
  2. type python
  3. if it show that python version that installed in your pc.
  4. Then you don’t need to install python.
  5. Otherwise you have to install python.

To install python follow these steps:

For windows,

  1. Open a Web browser and go to https://www.python.org/downloads/.
  2. Follow the link for the Windows installer python-XYZ.msi file where XYZ is the version you need to install.
  3. To use this installer python-XYZ.msi, the Windows system must support Microsoft Installer 2.0. Save the installer file to your local machine and then run it to find out if your machine supports MSI.
  4. Run the downloaded file. This brings up the Python install wizard, which is really easy to use. Just accept the default settings, wait until the install is finished, and you are done.

For Linux / Unix,

  1. Open a Web browser and go to https://www.python.org/downloads/.
  2. Follow the link to download zipped source code available for Unix/Linux.
  3. Download and extract files.
  4. Editing the Modules/Setup file if you want to customize some options.
  5. run ./configure script
  6. make
  7. make install

This installs Python at standard location /usr/local/bin and its libraries at /usr/local/lib/pythonXX where XX is the version of Python.

Setting up PATH:

Python Syntax:

You have to know 5 things before you learn python.

Let’s get start to know about that essentials.

  1. We can run our python code in command prompt ( cmd in windows):
  2. Like this,

    C:\Users\ your name >python C:\Users\ your name >print(“Hellow word”) Hellow word
  3. We can also run a python file using the file location.
  4. C:\Users\ your name > python filename.py
  5. Another method:
  6. C:\Users\ your name > python C:\Users\ your name\filename.py

Python Indentation:

  • Indentation refers to the spaces at the beginning of a code line.
  • Where in other programming languages the indentation in code is for readability only, the Indentation in Python is very important.
  • Python uses indentation to indicate a block of code.

Example:

 If (20 > 2):
    print (‘true’)
  else:
    print (‘false’)

output:

    true

Syntax error:

  • You can choose the space count but it should be minimum 1.
  • You have to use same number of spaces in the same block, otherwise it will shows error.

Example:

  If (20 > 2):
   print (‘true’)
   print(’20 is greater than 2’)
 else:
   print (‘false’)

output:

   syntax error

Python Variables:

Variables are a storing element of data. We should assign the variable for the data which we will use in our programming.


Example:

  a = 10
  b = 10.0
  c = “hellow”
  print (a)
  print (b)
  print (c)

Output:


  10
  10.0
  Hellow

Python Comments:

Basically Comments are used to represent the what the code is or the code does.

Comments are always started with # symbol, rest of the line will be non excecutable.

Example:


  # This the comment
  a = 10 #integer
  b = 10.0 # float
  c = “hellow” #string
  print (a)
  print (b)
  print (c)

Output:


  10
  10.0
  Hellow

Another method:

We can also comment many number of lines in our python code.

Example:

‘’’
  This Para is commented
  This the comment
  ‘’’
  b = 10.0 # float
  c = “hellow” #string
  #print (a)
  print (b)
  print (c)

Output:


  10.0
  Hellow

Don’t forget these important things Python Aspirants.

Comments