Python
Programming
Gaming AIML Robotics
Datab Data
ase Science
Automati programm Applicatio Networkin
on ing ns g
Most in-demand programming languages
2021-2024
Differences Between Python and C
Python is simple
Python
What is Python…?
Python is a simple ,easy to learn, powerful, high level, object
oriented programming language
Python is a fast growing language.
Python is a general purpose programming language
Python is programming language as well as scripting
language
Python is also an Interpreted language
History
Python was created by Guido van Rossum , and first
released on February 20, 1991.
While you may know the python as a large snake, the name
of the Python programming language comes from an old
BBC television comedy sketch series called Monty Python's
Flying Circus.
Why do people use Python…?
Simple and Easy Syntax
Dynamically Typed
High level features
Open source
Multi-Purpose Programming
Huge Libraries
Less code
Features of python
Features
High level
Python language in comparison of machine
It is programmer friendly language
Programmers can easily understand or interpret or
compile the high level
It's free (open source)
Downloading and installing Python is free and easy
Source code is easily accessible
Python is 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
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.
Portability
Python programs are portable. i.e
We can migrate from one platform to another platform very
easily.
Python programs will provide same results on any plattform.
Dynamically typed language
In python there is no need to declare the type of a variable.
Whenever we assign a value to the variable, based on the value
the type will be allocated automatically.
Extensible
Python can be linked to components written in other languages
easily
Python extensions can be written in C and C++ for the standard
implementation of Python in C (also known as CPython)
The Java language implementation of Python is called Jython, so
extensions would be written using Java
Libraries
It supports Huge Libraries, Modules and Packages
Thus it encourages Program Modularity and Code Reusability
Interpreted and (Byte-) Compiled
Python is actually byte-compiled, resulting in an intermediate
form closer to machine language
Executes code line by line
This improves Python's performance
Memory Management, CPU and Debugging of becomes easier
Python Versions
There are two major Python versions
Python 2
Python 3
On 16 October 2000, Python 2.0 was released with many new
feature
On 3rd December 2008, Python 3.0 was released with more
testing and includes new features
Python version 3 is not backwardly compatible with python2
The latest version 3.10.5
Python is pre-installed on most Unix systems, including Linux
and MAC OS X
But for in Windows Operating Systems , user can download
from the https://www.python.org/downloads/from the above link
download latest version
How Can I Get Python
Python for Window/Mac/Unix/Linux is available from
www.python.org
From the above link download latest version of Python
IDE and Install, Recent version is Python 3.7.3
Set Up Installation
⮚ Step 1: Download Python
Go to python.org/downloads and then click on the button to download
the latest version of Python
⮚ Step 2: Run the .exe file
Run the .exe file that you just downloaded, and then follow the
installation instructions.
⮚ Step 3: Run a code in Python
You can run a code in Python via the Python IDLE.
A quick way to find your Python IDLE on Windows is by clicking
on the Start menu
Running Python
There are two ways to start Python
Interactive Mode
Script Mode
Interactive Mode
Also called as Shell Mode
It performs line by line execution
Instruction are given in front of python prompt ( >>>)
Python carries out the given instructions shows the
result there itself
We can type Python expressions into the Python shell
The interpreter immediately shows the result
>>> 2 + 3 =5
First program
Print function in Python is function that outputs to your
console window
⚫ At the prompt (>>>) type:
>>> print (“Hello, World!”)
>>> print (“Welcome to ACE “)
Output:
Hello, world!
Welcome to ACE
Script Mode
Entire program execution at a time
The concept of writing group of python statements into a
file, saving that file with the extension ‘.py’ and submitting
the entire file to the python interpreter at a time
The saved instruction are known as Python Script or
Python Program
Anaconda Installation
Character set
Characters are used to form words, numbers and expressions.
Characters are categorized as
Letters
Digits
Special characters
White spaces.
Letters: (Upper Case and Lower Case)
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
Digits: 0123456789
Special Characters:
’" ( ) * + - / : = ! & $ ; < > % ? , . ˆ # @ ˜ ‘ { } [ ] \ |
White Spaces: Blank Space, Horizontal Space, Carriage Return,
New Line.
INPUT Function
Input () : input function takes input from the user and returns it
You can assign (store) the result of input into a variable.
name=input("What is your name?")
age = input("How old are you? ")
print ("Your name is", name)
print ("Your age is", age)
Output:
What is your name? xyz
How old are you? 28
Your name is xyz
Your age is 28
TOKEN
The smallest individual unit in a program is known as token
Python language supports the different types of tokens that are as
follows:
Keywords (Reserved words) : True, False, None, class,
continue, break, if, elif , else, from, or, def, del, import, etc.
Identifier : User-defined names
Literals : String, Numeric, Boolean, Collection,
Delimeters or punctutator : ( ), { }, [ ], :, ., =, ;, +=, -=, *=,
/=, %=, etc.
Operators : +, -, *, **, /, %, <<, >>, etc.
Key Words
Keywords are the reserved words that have a special meaning.
We can not use a keyword as variable name, function name or
any other identifier.
They are used to define the syntax and structure of the Python
language.
In Python, keywords are case sensitive.
There are 36 keywords available.
All the keywords except True, False and None are in lower case
To view list of key words
help() function:
we can use the help() function to get the list of
keywords
help(“keywords”)
Variables
Python uses Dynamic typing.
That is, no need to Declare variables to be a specific type
Variables are used to store data
A Python variable is a reserved memory location to store
values
Variables take memory space based on the type of value we
assigning to them
Type()
It is used to identity the type of the object
Ex: a=64
print(“Type of a:”,type(a))
b=“CSM AIML ”
print(“Type of b:”, type(b))
c=2.3
print(“Type of c:”,type(c))
Output:
Type of a:<class ‘int'>
Type of b:<class ‘str’>
Type of c:<class ‘float’>
Literal
Literals are the constant values or the variable values used in a
Python code.
There are mainly five types of literals used in python:
String Literals
Numeric Literals
Boolean Literals
Special Literals
Collection Literals
String literals:
In Python, String literals are characterised either by single
quotation marks, or double quotation marks surrounding them.
The string literals can be Single line or Multiple line strings
Numeric literals:
Numeric Literals in Python can be of three numeric types:
int
float
complex
Int
Int can be defined as a collection of both positive and negative
integers (without decimals).
Float
Float can be defined as a collection of both positive and
negative floating point numbers (with decimals)
Complex
Complex numbers are the numbers having both a real and
imaginary part in the form of x +yj, where x is real and y is
imaginary.
Boolean literals:
Boolean literals can be either 0 or 1 i.e, either True or False.
Special literals.
None is a special literal defined in Python to specify the end of
a list or to represent a NULL value.
Literal Collections.
Beside Lists, Python supports Tuples and Dictionary to store a
collection of literals in a single variable.
Operators
Operators are the symbols or words that perform some kind of operation on
given values (operands) in an expression and returns the result.
Operators are divided into:
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Identity operators
Membership operators
Bitwise operators
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
Identity Operators
Membership Operators
Bitwise Operators