SlideShare a Scribd company logo
Faculty of Engineering Science & Technology(FEST)
Hamdard Institute of Engineering Technology(HIET)
Hamdard University
Instructor
ABDUL HASEEB
HANDS-ON WORKSHOP ON PYTHON
PROGRAMMING LANGUAGE
(Day -1)
Faculty Development Program (Session-10)
The Python Programming Language
Audience
• Having basic understanding of programming or worked
on any High Level language like C, JAVA, or C ++, etc
At the end of today`s session you will be able to:
• Understand the significance of Python Programming
• Familiarize with the Python IDE Environment
• Understand the Input and Output operations in Python
• Use variables in Python language
What is Python Programming
• Python was developed by Guido van Rossum
(a Dutch programmer) in 1991
• Python is a High Level Language (whereas C and
Java are not High Level Language)
• Python has a design philosophy that emphasizes
Code Readability
• The syntax allows programmer to express
concepts in fewer lines of code than might be
used in languages such as C++, Java etc
Why Python Programming
According to IEEE Spectrum the top Programming Languages in
2017 are:
http://spectrum.ieee.org/computing/software/the-2017-top-programming-languages
Because it Easy to learn and use: Its simple
syntax is very accessible to programming
novices and will look familiar to anyone with
experience in Matlab, C/C++, Java. Also
Python has powerful libraries
Why Python Programming
• Because it is FREE
There is no worried of buying the key and or unethical use of software by
cracking its key
• Because it is Open Source
Why Python Programming
In the Open Source software the
source code, blue print and
documentation are freely available to
public. The software developer
voluntarily put their part to add the
features in the software
Python has vast development implementation
Python Cross-compilers to other languages
Python Web development frameworks
Python in other Science
Python has Powerful Libraries
Who uses Python
How to Learn Python
Working on Python IDLE
Download Python IDLE 2.x or 3.x from Python Software Foundation
Website for Free
Python IDLE Environment
IDLE (Integrated Development Learning Environment)
• IDLE has multi-window text editor with syntax highlighting,
auto-completion, smart indent
• The Shell window execute command at the statement
complete
• User code written in Text Editor window
Some Useful command for Python IDLE Shell
window
• Alt + p to retrieve Previous Command
• Alt + n to retrieve Next Command
• To get help of instruction or command use
help(instruction)
Python IDLE Environment
My First Python Program
Open Python IDLE Shell window and write the following
instruction
A print is an output instruction use to display string or
data value on screen
print("Hamdard University")
Note: Program contain no header file, no main() function,
no semi column at instruction end, even you write string
in single quotation mark. BUT one thing common with
other programming language that is Case Sensitive
print('Hamdard University‘)
Output Instruction
Escape Sequence Working
 Backslash ()
' Single quote (')
" Double quote (")
n ASCII Linefeed (LF)
t ASCII Horizontal Tab (TAB)
Example:
>>>print('BackslashtTabnNewline')
Backslash Tab
Newline`
The following are the Escape Sequence use with
print instruction
Python Data types
Python has five standard data types
• Numbers(Integer and Float)
• String
• List (Array)
• Tuple (Constant Array)
• Dictionary
Variable Number type:
• Integer (whole number)
• Float (decimal point number)
• Character/String (ASCII format)
• Boolean (True and False)
Python Variable
• Type of Variable: Check the type of Variable
• Deleting Variable: Delete the declare variable
Syntax: del(variable_name)
>>> a = 2
>>> print(a)
2
>>> del(a)
>>> print(a)
NameError: name 'a' is not defined
Variable value Type command Result
a=2 type(a) <class 'int'>
b=3.5 type(b) <class 'float'>
c=’f’ type(c) <class 'str'>
d=’abc123’ type(d) <class 'str'>
type(True) <class 'bool'>
type(False) <class 'bool'>
Python is an Interpreter Language
Working Compiler Interpreter
Converting code Convert whole code Step by step
Translation time Slow Fast
Execution time Fast Slow
Programming Languages
C, Visual Basic, Java,
LabView etc
Python, Matlab, PHP, MS
Excel etc
Python Interpreter Example
In Interpreter, if code contains error it may run
partially and stop when error occurs. In the
following code Error is present in line number 7 that
is “d=B” where ‘B’ is not define before, so program
runs and execute up to that line.
Input Instruction
• Input Instruction: To take an input from user through
keyboard input() command is used, this instruction take
input from keyboard in the form of ASCII character and
store it the variable.
• Syntax:
take_input = input(1 Argument)
• Example:
name = input('Enter your name =')
age = input('Enter your age = ')
print('Your name is ', name , ',and your age is = ',age)
Python Version
• Python Version 1 is obsolete now
• Python Version 2 and Python Version 3 is active
• The Python 2 is old version but retain for programming
because lots of module was developed on it which not
work with Python 3
• There is only some difference in execution of
instructions other wise both have same working
Difference between Python 2 and Python 3
Output Instruction
Python 2 Python 3
Python 2 allows to write the print
instruction argument with in Round
bracket ( and) or with out it.
The argument of the print instruction must
written with in Round bracket ( and)
>>> print('String') #Allow
String
>>> print("String") #Allow
String
>>> print 'String' #Allow
String
>>> print "String" #Allow
String
>>> print('String') #Allow
String
>>> print("String") #Allow
String
>>> print 'String' #NotAllow
SyntaxError: Missing parentheses in call to 'print‘
>>> print "String" #NotAllow
SyntaxError: Missing parentheses in call to 'print‘
Difference between Python 2 and Python 3
Input Instruction
Python 2 Python 3
input(prompt) raw_input(prompt) Input(prompt)
It keeps the type of user
enter data
Automatically update the
Input variable to the user
enter data
Always take data in the
string format regardless of
the user enter data
Syntax:
Input_variable = input(prompt)
Input_variable data type is
same as user enter data
Syntax:
Input_variable = input(prompt)
Input_variable is String
Syntax:
Input_variable = input(prompt)
Input_variable is String
Input Instruction Example
Python 2 Python 3
input(prompt) raw_input(prompt) Input(prompt)
>>> a = input("Enter = ")
Enter = 12
>>> type(a)
<type 'int'>
>>> a = input("Enter = ")
Enter = 12.12
>>> type(a)
<type 'float'>
>>> a = input("Enter = ")
Enter = "Ab12"
>>> type(a)
<type 'str'>
>>> a = input("Enter = ")
Enter = Ab12
NameError: name 'Ab12' is not
defined
>>> a = raw_input("Enter = ")
Enter = 12
>>> type(a)
<type 'str'>
>>> a = raw_input("Enter = ")
Enter = 12.12
>>> type(a)
<type 'str'>
>>> a = raw_input("Enter = ")
Enter = "Ab12"
>>> type(a)
<type 'str'>
>>> a = raw_input("Enter = ")
Enter = Ab12
>>> type(a)
<type 'str'>
>>> a = input("Enter = ")
Enter = 12
>>> type(a)
<class 'str'>
>>> a = input("Enter = ")
Enter = 12.12
>>> type(a)
<class 'str'>
>>> a = input("Enter = ")
Enter = "Ab12"
>>> type(a)
<class 'str'>
>>> a = input("Enter = ")
Enter = Ab12
>>> type(a)
<class 'str'>
Difference between Python 2 and Python 3
Difference between Python 2 and Python 3
(problem and its solution)
Python 2 Python 3
Program
num = input('Enter a number = ')
print num,‘x 3 = ',num * 3
num = input('Enter a number = ')
print( num,‘x 3 = ',num * 3 )
Output
Enter a number = 5
5 x 3 = 15
Enter a number = 5
5 x 3 = 555
Observation: the num is integer so
number 5 x 3 is number 15
Observation: the num is String so String 5
x 3 is three times of number 5
The problem in the output of Python 3 is
solved in later slides
Change the variable type
Function Description
Example
Instruction Output
str(x) Converts object x to a string representation.
str(75)
str("25.25")
‘75’
'25.25'
int(x) Converts object x to a integer number.
int(35.26)
int(100.101 )
35
100
float(x) Converts object x to a float number.
float(35)
float(100)
35.0
100.0
list(s) Converts s to a list.
list(range(5,10))
list(range(1,10,2))
[5, 6, 7, 8, 9]
[1, 3, 5, 7, 9]
tuple(s) Converts s to a tuple.
tuple(range(5,10))
tuple(range(1,10,2))
(5, 6, 7, 8, 9)
(1, 3, 5, 7, 9)
dict(d)
Creates a dictionary. d must be a sequence
of (key,value) tuples.
chr(x) Converts an integer to a character.
chr(65)
chr(97)
'A‘
‘a’
ord(x) Converts a single character to its ASCII (integer value)
ord('A')
ord(‘a')
65
97
hex(x) Converts an integer to a hexadecimal string.
hex(16)
hex(100)
'0x10‘
'0x64'
oct(x) Converts an integer to an octal string.
oct(9)
oct(50)
'0o11‘
'0o62'
Exercise
Rewrite the following program in Python 3 with
correct output display
Without changing Variable Type Changing Variable Type
num = input(“Enter a number = “)
print( num,”x 3 = “,num * 3 )
num = input(“Enter a number = “)
print( num,“x 3 = ",int(num) * 3 )
3 x 3 = 333 3 x 3 = 9
Python IDEs
• Python IDLE
• PyCharm
• Sublime Text
• Atom
• Geany
• Anjuta
• Eric
• Komodo IDE
• KDevelop
• Ninja-IDE
•
• Spyder
Integer Operation
Function Description
bit_length(...)
Number of bits necessary to represent self in binary
Example: >>> (37).bit_length() 6
>>> int_num.bit_length() 2
bin(…)
Return binary of the integer
Example: >>> bin(37) '0b100101'
>>> bin(25) '0b1111111'
Denominator The denominator of a rational number in lowest terms
Imag The imaginary part of a complex number
numerator The numerator of a rational number in lowest terms
real The real part of a complex number
conjugate(...) Returns self, the complex conjugate of any int.
to_bytes(...) Return an array of bytes representing an integer.
Float Operation
Function Description
float.fromhex (...)
Create a floating-point number
from a hexadecimal string.
Example: >>>float.fromhex('0x1.ffffp10') 2047.984375
float.hex(…)
Return a hexadecimal representation of a floating-point number
Example: >>>3.14159.hex() '0x1.921f9f01b866ep+1'
is_integer(...)
Return True if the float is an integer
Example: >>> num = 5.5
>>> num.is_integer() False
>>> num = num - 0.5 # remove floating value
>>> num.is_integer() True
as_integer_ratio(...)
Return a pair of integers, whose ratio is exactly equal to the original float and
with a positive denominator.
Example: >>> (10.0).as_integer_ratio() (10, 1)
>>> (0.0).as_integer_ratio() (0, 1)
>>> (-.25).as_integer_ratio() (-1, 4)
conjugate(...) Return self, the complex conjugate of any float.
imag The imaginary part of a complex number
Real The real part of a complex number
String Operation
Function Description
len(string) Return length of string
capitalize(...)
Return a capitalized version of S, i.e. make the first character have upper
case and the rest lower case.
title(...)
Return a title cased version of S, i.e. words start with title case characters,
and all remaining cased characters have lower case.
lower(...) Return a copy of the string S converted to lowercase.
upper(...) Return a copy of S converted to uppercase.
casefold(...) Return a version of S suitable for caseless comparisons
islower(...)
Return True if all cased characters in S are lowercase and there is at least one
cased character in S, False otherwise.
isupper(...)
Return True if all cased characters in S are uppercase and there is at least
one cased character in S, False otherwise.
isnumeric(...) Return True if there are only numeric characters in S, False otherwise.
isdecimal(...) Return True if there are only decimal characters in S, False otherwise
isdigit(...)
Return True if all characters in S are digits and there is at least one character
in S, False otherwise.
a = input("Enter your name:")
print("Lower Case of Enter string = " ,a.lower())
print("Upper Case of Enter string = " , a.upper())
print("Title Case of Enter string = " , a.title())
print("Length of Enter string = " , len(a))
print("Your Enter string is Alpha = " , a.isalpha())
print("Your Enter string is Decimal = " , a.isdecimal())
print("Your Enter string is Digit = " , a.isdigit())
print("Your Enter string is in Lower case = " , a.islower())
print("Your Enter string is in Upper case = " , a.isupper())
print("Your Enter string is in Title case = " , a.istitle())
Output 1:
Enter your name:Hamdard university
Lower Case of Enter string = hamdard university
Upper Case of Enter string = HAMDARD UNIVERSITY
Title Case of Enter string = Hamdard University
Length of Enter string = 18
Your Enter string is Alpha = False
Your Enter string is Decimal = False
Your Enter string is Digit = False
Your Enter string is in Lower case = False
Your Enter string is in Upper case = False
Your Enter string is in Title case = False
Output 2:
Enter your name:123456
Lower Case of Enter string = 123456
Upper Case of Enter string = 123456
Title Case of Enter string = 123456
Length of Enter string = 6
Your Enter string is Alpha = False
Your Enter string is Decimal = True
Your Enter string is Digit = True
Your Enter string is in Lower case = False
Your Enter string is in Upper case = False
Your Enter string is in Title case = False
String Operation Example
Comparing Python with C/C++
Programming Parameter Python Language C/C++ Language
Programming type Interpreter Compiler
Programming Language High level Language Middle level Language
Header file import #include
Code block Whitespace Indentation
Code within curly bracket
{ code}
Single line statement
termination
Nothing Semicolon ;
Control flow (Multi line)
statement termination
Colon : Nothing
Single line comments # comments //comments
Multi-line comments
‘’’
Comments lines
‘’’
/*
Comments lines
*/
If error code found Partial run code until find error
Did not run until error is
present
Program length Take fewer lines Take relatively more lines
THANK YOU
Ad

Recommended

Advance python programming
Advance python programming
Jagdish Chavan
 
Object oriented approach in python programming
Object oriented approach in python programming
Srinivas Narasegouda
 
JAVA AWT
JAVA AWT
shanmuga rajan
 
Java: GUI
Java: GUI
Tareq Hasan
 
Inheritance in java
Inheritance in java
yash jain
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
What is Dictionary In Python? Python Dictionary Tutorial | Edureka
What is Dictionary In Python? Python Dictionary Tutorial | Edureka
Edureka!
 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Edureka!
 
Introduction to php
Introduction to php
shanmukhareddy dasi
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#
Dr.Neeraj Kumar Pandey
 
Javascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
Operators in python
Operators in python
eShikshak
 
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Scott Leberknight
 
Input output files in java
Input output files in java
Kavitha713564
 
Java Collections
Java Collections
Kongu Engineering College, Perundurai, Erode
 
Generics
Generics
Ravi_Kant_Sahu
 
JavaFX Presentation
JavaFX Presentation
Mochamad Taufik Mulyadi
 
Android Layout
Android Layout
mcanotes
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
Edureka!
 
Classes and objects
Classes and objects
Nilesh Dalvi
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Edureka!
 
Php mysql ppt
Php mysql ppt
Karmatechnologies Pvt. Ltd.
 
Constructor in java
Constructor in java
Pavith Gunasekara
 
SQLITE Android
SQLITE Android
Sourabh Sahu
 
ADO.NET
ADO.NET
Wani Zahoor
 
Event In JavaScript
Event In JavaScript
ShahDhruv21
 
Data Structures in Python
Data Structures in Python
Devashish Kumar
 
Chapter 05 classes and objects
Chapter 05 classes and objects
Praveen M Jigajinni
 
Python basics
Python basics
RANAALIMAJEEDRAJPUT
 
Python Programming Introduction demo.ppt
Python Programming Introduction demo.ppt
JohariNawab
 

More Related Content

What's hot (20)

Introduction to php
Introduction to php
shanmukhareddy dasi
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#
Dr.Neeraj Kumar Pandey
 
Javascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
Operators in python
Operators in python
eShikshak
 
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Scott Leberknight
 
Input output files in java
Input output files in java
Kavitha713564
 
Java Collections
Java Collections
Kongu Engineering College, Perundurai, Erode
 
Generics
Generics
Ravi_Kant_Sahu
 
JavaFX Presentation
JavaFX Presentation
Mochamad Taufik Mulyadi
 
Android Layout
Android Layout
mcanotes
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
Edureka!
 
Classes and objects
Classes and objects
Nilesh Dalvi
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Edureka!
 
Php mysql ppt
Php mysql ppt
Karmatechnologies Pvt. Ltd.
 
Constructor in java
Constructor in java
Pavith Gunasekara
 
SQLITE Android
SQLITE Android
Sourabh Sahu
 
ADO.NET
ADO.NET
Wani Zahoor
 
Event In JavaScript
Event In JavaScript
ShahDhruv21
 
Data Structures in Python
Data Structures in Python
Devashish Kumar
 
Chapter 05 classes and objects
Chapter 05 classes and objects
Praveen M Jigajinni
 

Similar to Python programming workshop session 1 (20)

Python basics
Python basics
RANAALIMAJEEDRAJPUT
 
Python Programming Introduction demo.ppt
Python Programming Introduction demo.ppt
JohariNawab
 
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
manikamr074
 
Python knowledge ,......................
Python knowledge ,......................
sabith777a
 
Chapter1 python introduction syntax general
Chapter1 python introduction syntax general
ssuser77162c
 
Data Structure and Algorithms (DSA) with Python
Data Structure and Algorithms (DSA) with Python
epsilonice
 
Lecture1_introduction to python.pptx
Lecture1_introduction to python.pptx
MohammedAlYemeni1
 
Spsl iv unit final
Spsl iv unit final
Sasidhar Kothuru
 
Spsl iv unit final
Spsl iv unit final
Sasidhar Kothuru
 
Python_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. tx
vishwanathgoudapatil1
 
Python-Beginer-PartOnePython is one of the top programming languages in the w...
Python-Beginer-PartOnePython is one of the top programming languages in the w...
ahmedosman389
 
Python (3).pdf
Python (3).pdf
samiwaris2
 
Introduction to Python and Basic Syntax.pptx
Introduction to Python and Basic Syntax.pptx
GevitaChinnaiah
 
Introduction to Python Programming – Part I.pptx
Introduction to Python Programming – Part I.pptx
shakkarikondas
 
Revision of the basics of python - KVSRO Patna.pdf
Revision of the basics of python - KVSRO Patna.pdf
Manas Samantaray
 
Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1
ssusera7a08a
 
Revision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdf
optimusnotch44
 
Hands on Session on Python
Hands on Session on Python
Sumit Raj
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
Python Programming Introduction demo.ppt
Python Programming Introduction demo.ppt
JohariNawab
 
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
manikamr074
 
Python knowledge ,......................
Python knowledge ,......................
sabith777a
 
Chapter1 python introduction syntax general
Chapter1 python introduction syntax general
ssuser77162c
 
Data Structure and Algorithms (DSA) with Python
Data Structure and Algorithms (DSA) with Python
epsilonice
 
Lecture1_introduction to python.pptx
Lecture1_introduction to python.pptx
MohammedAlYemeni1
 
Python_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. tx
vishwanathgoudapatil1
 
Python-Beginer-PartOnePython is one of the top programming languages in the w...
Python-Beginer-PartOnePython is one of the top programming languages in the w...
ahmedosman389
 
Python (3).pdf
Python (3).pdf
samiwaris2
 
Introduction to Python and Basic Syntax.pptx
Introduction to Python and Basic Syntax.pptx
GevitaChinnaiah
 
Introduction to Python Programming – Part I.pptx
Introduction to Python Programming – Part I.pptx
shakkarikondas
 
Revision of the basics of python - KVSRO Patna.pdf
Revision of the basics of python - KVSRO Patna.pdf
Manas Samantaray
 
Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1
ssusera7a08a
 
Revision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdf
optimusnotch44
 
Hands on Session on Python
Hands on Session on Python
Sumit Raj
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
Ad

More from Abdul Haseeb (9)

Python workshop session 6
Python workshop session 6
Abdul Haseeb
 
Python programming workshop session 4
Python programming workshop session 4
Abdul Haseeb
 
Python programming workshop session 3
Python programming workshop session 3
Abdul Haseeb
 
Python programming workshop session 2
Python programming workshop session 2
Abdul Haseeb
 
Environmental Friendly Coal Power Plants
Environmental Friendly Coal Power Plants
Abdul Haseeb
 
Low Voltage Circuit Breaker
Low Voltage Circuit Breaker
Abdul Haseeb
 
Proteus Circuit Simulation
Proteus Circuit Simulation
Abdul Haseeb
 
Waste Heat Recovery  System in Cement Plant
Waste Heat Recovery  System in Cement Plant
Abdul Haseeb
 
Environmental Friendly Coal Power Plants
Environmental Friendly Coal Power Plants
Abdul Haseeb
 
Python workshop session 6
Python workshop session 6
Abdul Haseeb
 
Python programming workshop session 4
Python programming workshop session 4
Abdul Haseeb
 
Python programming workshop session 3
Python programming workshop session 3
Abdul Haseeb
 
Python programming workshop session 2
Python programming workshop session 2
Abdul Haseeb
 
Environmental Friendly Coal Power Plants
Environmental Friendly Coal Power Plants
Abdul Haseeb
 
Low Voltage Circuit Breaker
Low Voltage Circuit Breaker
Abdul Haseeb
 
Proteus Circuit Simulation
Proteus Circuit Simulation
Abdul Haseeb
 
Waste Heat Recovery  System in Cement Plant
Waste Heat Recovery  System in Cement Plant
Abdul Haseeb
 
Environmental Friendly Coal Power Plants
Environmental Friendly Coal Power Plants
Abdul Haseeb
 
Ad

Recently uploaded (20)

ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
Code Profiling in Odoo 18 - Odoo 18 Slides
Code Profiling in Odoo 18 - Odoo 18 Slides
Celine George
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
Hurricane Helene Application Documents Checklists
Hurricane Helene Application Documents Checklists
Mebane Rash
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
Pests of Maize: An comprehensive overview.pptx
Pests of Maize: An comprehensive overview.pptx
Arshad Shaikh
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
A Visual Introduction to the Prophet Jeremiah
A Visual Introduction to the Prophet Jeremiah
Steve Thomason
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
Birnagar High School Platinum Jubilee Quiz.pptx
Birnagar High School Platinum Jubilee Quiz.pptx
Sourav Kr Podder
 
INDUCTIVE EFFECT slide for first prof pharamacy students
INDUCTIVE EFFECT slide for first prof pharamacy students
SHABNAM FAIZ
 
This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
 
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
parmarjuli1412
 
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
jutaydeonne
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
Code Profiling in Odoo 18 - Odoo 18 Slides
Code Profiling in Odoo 18 - Odoo 18 Slides
Celine George
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
Hurricane Helene Application Documents Checklists
Hurricane Helene Application Documents Checklists
Mebane Rash
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
Pests of Maize: An comprehensive overview.pptx
Pests of Maize: An comprehensive overview.pptx
Arshad Shaikh
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
A Visual Introduction to the Prophet Jeremiah
A Visual Introduction to the Prophet Jeremiah
Steve Thomason
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
Birnagar High School Platinum Jubilee Quiz.pptx
Birnagar High School Platinum Jubilee Quiz.pptx
Sourav Kr Podder
 
INDUCTIVE EFFECT slide for first prof pharamacy students
INDUCTIVE EFFECT slide for first prof pharamacy students
SHABNAM FAIZ
 
This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
 
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
parmarjuli1412
 
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
jutaydeonne
 

Python programming workshop session 1

  • 1. Faculty of Engineering Science & Technology(FEST) Hamdard Institute of Engineering Technology(HIET) Hamdard University Instructor ABDUL HASEEB HANDS-ON WORKSHOP ON PYTHON PROGRAMMING LANGUAGE (Day -1) Faculty Development Program (Session-10)
  • 2. The Python Programming Language Audience • Having basic understanding of programming or worked on any High Level language like C, JAVA, or C ++, etc At the end of today`s session you will be able to: • Understand the significance of Python Programming • Familiarize with the Python IDE Environment • Understand the Input and Output operations in Python • Use variables in Python language
  • 3. What is Python Programming • Python was developed by Guido van Rossum (a Dutch programmer) in 1991 • Python is a High Level Language (whereas C and Java are not High Level Language) • Python has a design philosophy that emphasizes Code Readability • The syntax allows programmer to express concepts in fewer lines of code than might be used in languages such as C++, Java etc
  • 4. Why Python Programming According to IEEE Spectrum the top Programming Languages in 2017 are: http://spectrum.ieee.org/computing/software/the-2017-top-programming-languages
  • 5. Because it Easy to learn and use: Its simple syntax is very accessible to programming novices and will look familiar to anyone with experience in Matlab, C/C++, Java. Also Python has powerful libraries Why Python Programming
  • 6. • Because it is FREE There is no worried of buying the key and or unethical use of software by cracking its key • Because it is Open Source Why Python Programming In the Open Source software the source code, blue print and documentation are freely available to public. The software developer voluntarily put their part to add the features in the software
  • 7. Python has vast development implementation
  • 8. Python Cross-compilers to other languages
  • 10. Python in other Science
  • 11. Python has Powerful Libraries
  • 13. How to Learn Python
  • 14. Working on Python IDLE Download Python IDLE 2.x or 3.x from Python Software Foundation Website for Free
  • 15. Python IDLE Environment IDLE (Integrated Development Learning Environment) • IDLE has multi-window text editor with syntax highlighting, auto-completion, smart indent • The Shell window execute command at the statement complete • User code written in Text Editor window
  • 16. Some Useful command for Python IDLE Shell window • Alt + p to retrieve Previous Command • Alt + n to retrieve Next Command • To get help of instruction or command use help(instruction) Python IDLE Environment
  • 17. My First Python Program Open Python IDLE Shell window and write the following instruction A print is an output instruction use to display string or data value on screen print("Hamdard University") Note: Program contain no header file, no main() function, no semi column at instruction end, even you write string in single quotation mark. BUT one thing common with other programming language that is Case Sensitive print('Hamdard University‘)
  • 18. Output Instruction Escape Sequence Working Backslash () ' Single quote (') " Double quote (") n ASCII Linefeed (LF) t ASCII Horizontal Tab (TAB) Example: >>>print('BackslashtTabnNewline') Backslash Tab Newline` The following are the Escape Sequence use with print instruction
  • 19. Python Data types Python has five standard data types • Numbers(Integer and Float) • String • List (Array) • Tuple (Constant Array) • Dictionary Variable Number type: • Integer (whole number) • Float (decimal point number) • Character/String (ASCII format) • Boolean (True and False)
  • 20. Python Variable • Type of Variable: Check the type of Variable • Deleting Variable: Delete the declare variable Syntax: del(variable_name) >>> a = 2 >>> print(a) 2 >>> del(a) >>> print(a) NameError: name 'a' is not defined Variable value Type command Result a=2 type(a) <class 'int'> b=3.5 type(b) <class 'float'> c=’f’ type(c) <class 'str'> d=’abc123’ type(d) <class 'str'> type(True) <class 'bool'> type(False) <class 'bool'>
  • 21. Python is an Interpreter Language Working Compiler Interpreter Converting code Convert whole code Step by step Translation time Slow Fast Execution time Fast Slow Programming Languages C, Visual Basic, Java, LabView etc Python, Matlab, PHP, MS Excel etc
  • 22. Python Interpreter Example In Interpreter, if code contains error it may run partially and stop when error occurs. In the following code Error is present in line number 7 that is “d=B” where ‘B’ is not define before, so program runs and execute up to that line.
  • 23. Input Instruction • Input Instruction: To take an input from user through keyboard input() command is used, this instruction take input from keyboard in the form of ASCII character and store it the variable. • Syntax: take_input = input(1 Argument) • Example: name = input('Enter your name =') age = input('Enter your age = ') print('Your name is ', name , ',and your age is = ',age)
  • 24. Python Version • Python Version 1 is obsolete now • Python Version 2 and Python Version 3 is active • The Python 2 is old version but retain for programming because lots of module was developed on it which not work with Python 3 • There is only some difference in execution of instructions other wise both have same working
  • 25. Difference between Python 2 and Python 3 Output Instruction Python 2 Python 3 Python 2 allows to write the print instruction argument with in Round bracket ( and) or with out it. The argument of the print instruction must written with in Round bracket ( and) >>> print('String') #Allow String >>> print("String") #Allow String >>> print 'String' #Allow String >>> print "String" #Allow String >>> print('String') #Allow String >>> print("String") #Allow String >>> print 'String' #NotAllow SyntaxError: Missing parentheses in call to 'print‘ >>> print "String" #NotAllow SyntaxError: Missing parentheses in call to 'print‘
  • 26. Difference between Python 2 and Python 3 Input Instruction Python 2 Python 3 input(prompt) raw_input(prompt) Input(prompt) It keeps the type of user enter data Automatically update the Input variable to the user enter data Always take data in the string format regardless of the user enter data Syntax: Input_variable = input(prompt) Input_variable data type is same as user enter data Syntax: Input_variable = input(prompt) Input_variable is String Syntax: Input_variable = input(prompt) Input_variable is String
  • 27. Input Instruction Example Python 2 Python 3 input(prompt) raw_input(prompt) Input(prompt) >>> a = input("Enter = ") Enter = 12 >>> type(a) <type 'int'> >>> a = input("Enter = ") Enter = 12.12 >>> type(a) <type 'float'> >>> a = input("Enter = ") Enter = "Ab12" >>> type(a) <type 'str'> >>> a = input("Enter = ") Enter = Ab12 NameError: name 'Ab12' is not defined >>> a = raw_input("Enter = ") Enter = 12 >>> type(a) <type 'str'> >>> a = raw_input("Enter = ") Enter = 12.12 >>> type(a) <type 'str'> >>> a = raw_input("Enter = ") Enter = "Ab12" >>> type(a) <type 'str'> >>> a = raw_input("Enter = ") Enter = Ab12 >>> type(a) <type 'str'> >>> a = input("Enter = ") Enter = 12 >>> type(a) <class 'str'> >>> a = input("Enter = ") Enter = 12.12 >>> type(a) <class 'str'> >>> a = input("Enter = ") Enter = "Ab12" >>> type(a) <class 'str'> >>> a = input("Enter = ") Enter = Ab12 >>> type(a) <class 'str'> Difference between Python 2 and Python 3
  • 28. Difference between Python 2 and Python 3 (problem and its solution) Python 2 Python 3 Program num = input('Enter a number = ') print num,‘x 3 = ',num * 3 num = input('Enter a number = ') print( num,‘x 3 = ',num * 3 ) Output Enter a number = 5 5 x 3 = 15 Enter a number = 5 5 x 3 = 555 Observation: the num is integer so number 5 x 3 is number 15 Observation: the num is String so String 5 x 3 is three times of number 5 The problem in the output of Python 3 is solved in later slides
  • 29. Change the variable type Function Description Example Instruction Output str(x) Converts object x to a string representation. str(75) str("25.25") ‘75’ '25.25' int(x) Converts object x to a integer number. int(35.26) int(100.101 ) 35 100 float(x) Converts object x to a float number. float(35) float(100) 35.0 100.0 list(s) Converts s to a list. list(range(5,10)) list(range(1,10,2)) [5, 6, 7, 8, 9] [1, 3, 5, 7, 9] tuple(s) Converts s to a tuple. tuple(range(5,10)) tuple(range(1,10,2)) (5, 6, 7, 8, 9) (1, 3, 5, 7, 9) dict(d) Creates a dictionary. d must be a sequence of (key,value) tuples. chr(x) Converts an integer to a character. chr(65) chr(97) 'A‘ ‘a’ ord(x) Converts a single character to its ASCII (integer value) ord('A') ord(‘a') 65 97 hex(x) Converts an integer to a hexadecimal string. hex(16) hex(100) '0x10‘ '0x64' oct(x) Converts an integer to an octal string. oct(9) oct(50) '0o11‘ '0o62'
  • 30. Exercise Rewrite the following program in Python 3 with correct output display Without changing Variable Type Changing Variable Type num = input(“Enter a number = “) print( num,”x 3 = “,num * 3 ) num = input(“Enter a number = “) print( num,“x 3 = ",int(num) * 3 ) 3 x 3 = 333 3 x 3 = 9
  • 31. Python IDEs • Python IDLE • PyCharm • Sublime Text • Atom • Geany • Anjuta • Eric • Komodo IDE • KDevelop • Ninja-IDE • • Spyder
  • 32. Integer Operation Function Description bit_length(...) Number of bits necessary to represent self in binary Example: >>> (37).bit_length() 6 >>> int_num.bit_length() 2 bin(…) Return binary of the integer Example: >>> bin(37) '0b100101' >>> bin(25) '0b1111111' Denominator The denominator of a rational number in lowest terms Imag The imaginary part of a complex number numerator The numerator of a rational number in lowest terms real The real part of a complex number conjugate(...) Returns self, the complex conjugate of any int. to_bytes(...) Return an array of bytes representing an integer.
  • 33. Float Operation Function Description float.fromhex (...) Create a floating-point number from a hexadecimal string. Example: >>>float.fromhex('0x1.ffffp10') 2047.984375 float.hex(…) Return a hexadecimal representation of a floating-point number Example: >>>3.14159.hex() '0x1.921f9f01b866ep+1' is_integer(...) Return True if the float is an integer Example: >>> num = 5.5 >>> num.is_integer() False >>> num = num - 0.5 # remove floating value >>> num.is_integer() True as_integer_ratio(...) Return a pair of integers, whose ratio is exactly equal to the original float and with a positive denominator. Example: >>> (10.0).as_integer_ratio() (10, 1) >>> (0.0).as_integer_ratio() (0, 1) >>> (-.25).as_integer_ratio() (-1, 4) conjugate(...) Return self, the complex conjugate of any float. imag The imaginary part of a complex number Real The real part of a complex number
  • 34. String Operation Function Description len(string) Return length of string capitalize(...) Return a capitalized version of S, i.e. make the first character have upper case and the rest lower case. title(...) Return a title cased version of S, i.e. words start with title case characters, and all remaining cased characters have lower case. lower(...) Return a copy of the string S converted to lowercase. upper(...) Return a copy of S converted to uppercase. casefold(...) Return a version of S suitable for caseless comparisons islower(...) Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise. isupper(...) Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise. isnumeric(...) Return True if there are only numeric characters in S, False otherwise. isdecimal(...) Return True if there are only decimal characters in S, False otherwise isdigit(...) Return True if all characters in S are digits and there is at least one character in S, False otherwise.
  • 35. a = input("Enter your name:") print("Lower Case of Enter string = " ,a.lower()) print("Upper Case of Enter string = " , a.upper()) print("Title Case of Enter string = " , a.title()) print("Length of Enter string = " , len(a)) print("Your Enter string is Alpha = " , a.isalpha()) print("Your Enter string is Decimal = " , a.isdecimal()) print("Your Enter string is Digit = " , a.isdigit()) print("Your Enter string is in Lower case = " , a.islower()) print("Your Enter string is in Upper case = " , a.isupper()) print("Your Enter string is in Title case = " , a.istitle()) Output 1: Enter your name:Hamdard university Lower Case of Enter string = hamdard university Upper Case of Enter string = HAMDARD UNIVERSITY Title Case of Enter string = Hamdard University Length of Enter string = 18 Your Enter string is Alpha = False Your Enter string is Decimal = False Your Enter string is Digit = False Your Enter string is in Lower case = False Your Enter string is in Upper case = False Your Enter string is in Title case = False Output 2: Enter your name:123456 Lower Case of Enter string = 123456 Upper Case of Enter string = 123456 Title Case of Enter string = 123456 Length of Enter string = 6 Your Enter string is Alpha = False Your Enter string is Decimal = True Your Enter string is Digit = True Your Enter string is in Lower case = False Your Enter string is in Upper case = False Your Enter string is in Title case = False String Operation Example
  • 36. Comparing Python with C/C++ Programming Parameter Python Language C/C++ Language Programming type Interpreter Compiler Programming Language High level Language Middle level Language Header file import #include Code block Whitespace Indentation Code within curly bracket { code} Single line statement termination Nothing Semicolon ; Control flow (Multi line) statement termination Colon : Nothing Single line comments # comments //comments Multi-line comments ‘’’ Comments lines ‘’’ /* Comments lines */ If error code found Partial run code until find error Did not run until error is present Program length Take fewer lines Take relatively more lines