The Introduction to Python Programming Language

Python is an example of a high level language.Other high level languages you might have heard of are C++,PHP,Pascal,C#,and Java. Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming.

Install Python

Installing Python is generally easy. Nowadays many Linux and UNIX distributions include a recent Python. Even some Windows computers (notably those from HP) now come with Python already installed. If you do need to install Python, you can download from Python official website.

The engine that translates and runs Python is called the Python Interpreter . There are two ways to use it:

  1. Immediate mode
  2. Script mode

1. Immediate mode:

In the mode,you type Python expressions into the Python Interpreter window, and the interpreter immediately shows the results.
For example:

>>>2+2   #User input
4    #The interpreter responds with this

The >>> is called the Python prompt. The interpreter users the prompt to indicate that it is ready for instructions . We type 2+2 , and the interpreter evaluated our expression, and replied 4, and on next line it gave a new prompt ,indicating that it is ready for more input.

2. Script mode:

Alternatively, You can write a program in a file and use the interpreter to execute the contents of the file. Such a file is called a script.

Application of Python:

  1. Numerous Areas
  2. Web Programming
  3. Scripting
  4. Scientific Computing
  5. Artificial Intelligence(AI)

Example

Write a program in Python to sum of two number.

Program:

print("My first program adds two number")
a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
c=int(a+b)
print("Sum of two number: ",+c)

Comments:

A comment in a computer program is text that is intended only for the human reader — it is completely ignored by the interpreter.

In Python, the # token starts a comment. The rest of the line is ignored. Here is a new version of Hello, World!.

#---------------------------------------------------
#This program shows the comment line in Python
#---------------------------------------------------

print("Hello, World!")     # For print any massage

Variables & Data types:

A value is one of the fundamental things — like a letter or a number — that a program manipulates. The values we have seen so far are 4 (the result when we added 2 + 2), and "Hello, World!".
These values are classified into different classes, or data types: 4 is an integer, and "Hello, World!" is a string, so-called because it contains a string of letters. You (and the interpreter) can identify strings because they are enclosed in quotation marks.
If you are not sure what class a value falls into, Python has a function called type which can tell you.
In Immediate mode:

>>> type("Hello, World!")
<class 'str'>
>>> type(17)
<class 'int'>

In Script mode:

a=type(4)
print("first is ",a)
b=type("Hello, World!")
print("Second is ",b)

Output:

first is <class 'int'>
Second is <class 'str'>


Related Article