0% found this document useful (0 votes)
3 views44 pages

Python Introduction

Python is a high-level, interpreted, and object-oriented programming language that is simple and beginner-friendly. Developed by Guido Van Rossum and released in 1991, it supports multiple programming paradigms and is widely used in various applications including web development, data analysis, and machine learning. While Python is open-source and has extensive libraries, it is slower than languages like C and C++ and does not check variable types at compile time.

Uploaded by

Anish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views44 pages

Python Introduction

Python is a high-level, interpreted, and object-oriented programming language that is simple and beginner-friendly. Developed by Guido Van Rossum and released in 1991, it supports multiple programming paradigms and is widely used in various applications including web development, data analysis, and machine learning. While Python is open-source and has extensive libraries, it is slower than languages like C and C++ and does not check variable types at compile time.

Uploaded by

Anish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

INTRODUCTION TO PYTHON

• Introduction:
• Python is a general purpose high-level, interpreted, interactive and object-
oriented scripting language.

It uses English keywords frequently where as other languages use punctuation,


and it has fewer syntactical constructions than other languages.

• Python is recommended as first programming language for beginners.


• Python is object oriented, high level, open source, interpreter based
programming language.
• It is very simple and easy to use.
• Python supports multiple programming pattern, including object
oriented programming.
Eg: To print Helloworld:
Java:
public class HelloWorld
{ In python
p s v main(String[] args) print("Hello World")
{
SOP("Hello world");
}}
In C:
#include<stdio.h>
void main()
{printf("Hello world");}
• History of Python

• Python was developed by Guido Van Rossam in 1989 while working at National Research
Institute at Netherlands.

• But officially Python was made available to public in 1991. The official Date of Birth for
Python is : Feb 20th 1991.

• Python is derived from many other languages, including ABC, Modula-3, C, C++, Algol-68, SmallTalk,
Unix shell, and other scripting languages.
• In Python:
• The name Python was selected from the TV Show"The Complete
Monty Python’s Circus", which was broadcasted in BBC from 1969 to
1974.
• Guido developed Python language by taking almost all programming
features from different languages
1. Functional Programming Features from C
2. Object Oriented Programming Features from C++
3. Scripting Language Features from Perl and Shell Script
4. Modular Programming Features from Modula-3
• Most of syntax in Python Derived from C and ABC languages.
Where we can use Python:
We can use everywhere. The most common important application areas
are
1. For developing Desktop Applications
2. For developing web Applications
3. For developing database Applications
4. For Network Programming
5. For developing games
6. For Data Analysis Applications
7. For Machine Learning
8. For developing Artificial Intelligence Applications
9. For IOT
• Disadvantages of Python
• Python is not as fast as C and C++, It means it is slower than C/C++:
• Does not check variable type at compile time. It use dynamic type so
flexible that Python interpreter cannot check the type for mismatch
at the compile time.
Who Uses Python Today?
1. Google makes extensive use of Python in its web search systems.
2. The popular YouTube video sharing service is largely written in Python.
3. The Dropbox storage service codes both its server and desktop client
software primarily in Python.
4. The Raspberry Pi single-board computer promotes Python as its
educational language.
5. The widespread BitTorrent peer-to-peer file sharing system began its life
as a Python program.
6. Google‘s App Engine web development framework uses Python as an
application language.
7. Maya, a powerful integrated 3D modeling and animation system,
provides a Python scripting API.
8. Intel, Cisco, Hewlett-Packard, Seagate, Qualcomm, and IBM use Python
for hardware testing.
9. NASA, Los Alamos, Fermilab, JPL, and others use Python for scientific
programming tasks.
Features of Python

• Python is an object-oriented, high level language,


interpreted, dynamic and multipurpose programming
language.
• There are a lot of features provided by python
programming language. Some features of python are given
below;
1. Simple and easy to learn:

• Python is a simple programming language. When we read


Python program, we can feel like reading english
statements.
• The syntaxes are very simple and only 30+ keywords are
available.
• When compared with other languages, we can write
programs with very less number of lines. Hence more
readability and simplicity.
• We can reduce development and cost of the project.
2. Freeware and Open Source:
• We can use Python software without any licence and it is
freeware.

• Its source code is open,so that we can we can customize based


on our requirement.

• Eg: Jython is customized version of Python to work with Java


Applications.

• Python language is freely available at www.python.org.


• The source-code is also available. Therefore it is open source.
3. High Level Programming language:
• Python is high level programming language and hence it is
programmer friendly language. Being a programmer we are not
required to concentrate low level activities like memory
management and security etc..

4. Platform Independent:
• Once we write a Python program,it can run on any platform
without rewriting once again.
• Internally PVM is responsible to convert into machine
understandable form.
5. Portability:
• Python programs are portable. ie we can migrate from one platform
to another platform very easily. Python programs will provide same
results on any platform.

6. Dynamically Typed:
In Python we are not required to declare type for variables.
Whenever we are assigning the value, based on value, type will be
allocated automatically. Hence Python is considered as dynamically
typed language.

• But Java, C etc are Statically Typed Languages b'z we have to provide
type at the beginning only.
• This dynamic typing nature will provide more flexibility to the
programmer.
7.Both Procedure Oriented and Object Oriented:
• Python language supports both Procedure oriented (like C,
pascal etc) and object oriented (like C++,Java) features.
Hence we can get benefits of both like security and
reusability etc

8. Interpreted:
• We are not required to compile Python programs explcitly.
Internally Python interpreter will take care that
compilation.
• If compilation fails interpreter raised syntax errors. Once
compilation success then PVM (Python Virtual Machine) is
responsible to execute.
9. Embedded:
• We can use Python programs in any other language
programs.
• i.e we can embedd Python programs anywhere.

10. Extensive Library:


• Python has a rich inbuilt library.
• Being a programmer we can use this library directly and we
are not responsible to implement the functionality.
Limitations of Python(Disadvantages of Python):
1. Performance wise not up to the mark because it is interpreted
language.
2. Not using for mobile Applications.
3. Python is not as fast as C and C++, It means it is slower than C/C++:
4. Does not check variable type at compile time. It use dynamic type
so flexible that Python interpreter cannot check the type for
mismatch at the compile time.
Flavors of Python:
1.CPython:
• It is the standard flavor of Python. It can be used to work with C language
Applications.

2.Jython or JPython:
• It is for Java Applications. It can run on JVM.

3. IronPython:
• It is for C#.Net platform.
4.PyPy:
• The main advantage of PyPy is performance will be improved because JIT
compiler is available inside PVM.

5.Ruby Python:
• For Ruby Platforms.
Python Versions:
• Python 1.0V introduced in Jan 1994.
• Python 2.0V introduced in October 2000.
• Python 3.0V introduced in December 2008.

Note: Python 3 won't provide backward compatibility to Python2 i.e. there is no


guarantee that Python2 programs will run in Python3.

Current versions:
• Python 3.7.4 July 8, 2019
• Python 2.7.16 March 4, 2019
Other Versions:
• Python 3.6.9 July 2, 2019
• Python 2.7.15 May 1, 2018
• Python 3.6.1 March 21, 2017
• Python 2.7.13 April 9, 2012
Difference between Python 2 and Python 3

The two versions Python 2 and Python 3 are very much different from each other.
• A list of differences between Python 2 and Python 3 are given below:
• Python 2 uses print as a statement and used as print "something" to print some
string on the console.
• On the other hand, Python 3 uses print as a function and used as
print("something") to print something on the console.
• Python 2 uses the function raw_input() to accept the user's input. It
returns the string representing the value, which is typed by the user.

• To convert it into the integer, we need to use the int() function in


Python.
• Python 3 uses input() function to accept the user’s input().
• In Python 2, the implicit string type is ASCII, whereas, in Python 3, the
implicit string type is Unicode.
• How to Run Python Programs
• There are three way to execute python code :
• 1)Interactive Mode
• 2)Script Mode
• 3)Using IDE(integrated development environment)
God.py

1.Interactive interpreter prompt

• Python provides us the feature to execute the python statement one


by one at the interactive prompt. It is preferable in the case where we
are concerned about the output of each line of our python program.
• To open the interactive mode, open the terminal (or command
prompt) and type python (python3 in case if you have python2 and
python3 both installed on your system).
1.Interactive interpreter prompt
• Python provides us the feature to execute the python statement
one by one at the interactive prompt. It is preferable in the case
where one is concerned about the output of each line of our
python program.
• To open the interactive mode, open the terminal (or command
prompt) and type python.
• It will open the following prompt where one can execute the
python statement and check their impact on the console.
2.Using a script file
• Interpreter prompt is good to run the individual statements of the
code. However, one can not write the code every-time on the
terminal.
• one needs to write our code into a file which can be executed later.
For this purpose, open an editor like notepad, create a file named
first.py (python used .py extension)
• To run this file named as first.py, one needs to run the following
command on the terminal.
• $ python3 first.py
• 3.General Editors and IDEs with Python Support
• Eclipse + PyDev
• Sublime Text
• Atom
• GNU Emacs
• Vi / Vim
• Visual Studio
• Visual Studio Code
• Python-Specific Editors and IDEs
• PyCharm
• Spyder
• Thonny
Byte code Compilation:
• Python first compiles your source code (the statements in your
file) into a format known as byte code.
• Compilation is simply a translation step, and byte code is a
lower-level, platform independent representation of your source
code.
• Roughly, Python translates each of your source statements into a
group of byte code instructions by decomposing them into
individual steps.
• This byte code translation is performed to speed execution —byte
code can be run much more quickly than the original source code
statements in your text file.
The Python Virtual Machine:
• Once your program has been compiled to byte code (or the
byte code has been loaded from existing .pyc file), it is
shipped off for execution to something generally known as the
python virtual machine (PVM).
Print Hello World in Python

Python code save with .py extension.


Print hello world in python
a="Hello World!"
print(a)
Output
Hello World!
Identifiers
A name in Python program is called identifier.
It can be class name or function name or module name or variable
name.
a = 10
Rules to define identifiers in Python:
1. The only allowed characters in Python are
alphabet symbols(either lower case or upper case)
digits(0 to 9)
underscore symbol(_)
By mistake if we are using any other symbol like $ then we will get
syntax error.
cash = 10
ca$h =20
2. Identifier should not starts with digit
123total
total123
3. Identifiers are case sensitive. Of course Python language is
case sensitive language.
total=10
TOTAL=999
print(total) #10
print(TOTAL) #999
1.Alphabet Symbols (Either Upper case OR Lower case)
2. If Identifier is start with Underscore (_) then it indicates it is
private.
3. Identifier should not start with Digits.
4. Identifiers are case sensitive.
5. We cannot use reserved words as identifiers
Eg: def=10 
6. There is no length limit for Python identifiers. Bu no recommended
to use too lengthy identifiers.
7. Dollor ($) Symbol is not allowed in Python
Variables in Python

• Variables are used for store data on memory location


• Variables are nothing but reserved memory locations to store
values. This means that when you create a variable you
reserve some space in memory.
• Based on the data type of a variable, the interpreter allocates
memory and decides what can be stored in the reserved
memory. Therefore, by assigning different data types to
variables, you can store integers, decimals or characters in
these variables.
• Variable names can be a group of both letters and digits, but they
have to begin with a letter or an underscore.
• It is recomended to use lowercase letters for variable name. Rahul
and rahul both are two different variables.
Declaring Variable and Assigning Values

• Python does not bound us to declare variable before using in the


application. It allows us to create variable at required time.
• We don't need to declare explicitly variable in Python. When we assign
any value to the variable that variable is declared automatically.
• The equal (=) operator is used to assign value to a variable.
Multiple Assignment
• Python allows us to assign a value to multiple variables in a single
statement which is also known as multiple assignment.

• We can apply multiple assignments in two ways either by assigning


a single value to multiple variables or assigning multiple values to
multiple variables. Lets see given examples.
Multiple Assignments to variables :

• Python allows you to assign a single value to several variables


simultaneously.
• For example –
•a=b=c=1
• Here, an integer object is created with the value 1, and all three
variables are assigned to the same memory location. You can
also assign multiple objects to multiple variables.
• For example –
• a, b, c = 1, 2.5, ”mothi”
• Here, two integer objects with values 1 and 2 are assigned to
variables a and b respectively, and one string object with the
value "john" is assigned to the variable c.
example

a,b,c=5,10,15
print a
print b
print c
Keywords in Python(Reserved Words)

• The following list shows the Python keywords.

• These are reserved words and you cannot use them as constant
or variable or any other identifier names.
• In Python some words are reserved to represent some meaning or
functionality. Such type of words are called Reserved words.
• There are 33 reserved words available in Python.
1. True,False,None
2. and, or ,not,is
3. if,elif,else while,for,break,continue,return,in,yield
4. try,except,finally,raise,assert
5. import,from,as,class,def,pass,global,nonlocal,lambda,del,with

If want see the keyword list type the following


import keyword
keyword.kwlist
All Reserved words in Python contain only alphabet symbols.
Except the following 3 reserved words, all contain only lower case
alphabet symbols.
True, False,None

You might also like