Introduction To Python Programming
Introduction To Python Programming
Introduction
History of Python
Python is a high level programming language developed by
Guido Rossum in 1989 at National Research Institute for
Mathematics and Computer Science in Netherlands.
Python became a popular programming language, widely used
in both industry and academia because of its simple, concise
and extensive support of libraries.
Advantages of Python
COBOL, C, C++ and Java are a few of the many programming
languages available. So, why Python??
There are some well-known advantages of Python language
which make it a popular programming language. These are given
below:
1. Readability: Readability of the code is most crucial factors in
programming. The longest part of any software’s life cycle is
maintenance. If a software has a highly readable code, then it is
easier to maintain and update the software. Python offers more
readability of code when compared to other programming
languages.
Advantages of Python
2. Portability: Python is platform independent i.e., it runs on all
platforms. The language is designed for portability.
3. Vast support of libraries: Python has a large collection of in-built
functionalities called standard library functions e.g., NumPy
provide support for large, multidimensional arrays and matrices.
4. Software integration: It can easily extend communicate and
integrate with other languages. Python code can invoke libraries of
C and C++ programming languages. It can also communicate with
Java and .net components.
Advantages of Python
5. Developer’s productivity: It is dynamically types language. There
is no need to declare variables explicitly. Also size of code written
is typically smaller than half of the code written in some other
languages such as C, C++ or Java.
As the size of code is reduced, there is less time to type and
debug. The amount of time needed to compile and execute the
code is also less.
Basics of Python Programming
Program written in any programming language consists of set of
instructions or statements. Here, all these instructions are written
using specific words and symbols according to the syntax rules or
the grammar of language.
Hence, every programmer should know these rules i.e., the syntax
supported by language for the proper execution of a program.
Python interactive shell
Python character set
Any Program written in Python contains words or statements
which follow a sequence of characters. When these characters are
submitted to the Python interpreter, they are interpreted or
uniquely identified in various contexts, such as characters,
identifiers, names, or constants.
Character Set:
Letters: Uppercase and lowercase
Digits: 0,1,2,…,9
Special symbols: _,+,-,&,$,#,:,;
White spaces: \t,\n etc.
Token
Python program consist of sequence of instructions. Python
break statement into a set of lexical components called
token. Each token corresponds to a substring of statements.
Python Tokens:
• Literals
• Keywords
• Identifiers/variables
• Operators
• Delimiters
Literals
Literals are numbers or strings or characters that appear directly in a
program.
E.g., 78 //Integer literal
• 24.78 // floating point literal
• ‘R’ //character literal
• “hello” // string literal
Python offers an in-built method called type to know the exact type of the literals.
e.g.
>>>type(‘hello’)
<class ‘str’>
>>>type (123)
<class ‘int’>
Keywords
Keywords are reserved words with fixed meaning assigned to them. Keywords can
not be used as identifiers or variables.