SlideShare a Scribd company logo
Compiler
Interpreter
2
/in/pcakhilnadh
3
8
x
Ox6745
y
100
x
Ox6745
Output	:	Y=	100
/in/pcakhilnadh
4
/in/pcakhilnadh
5
Output	:	Y=	100 Output	:	Y=	8
WHY	?
/in/pcakhilnadh
Introduction To
Python
Programming
6
Akhil Nadh PC
Before We
Get Started
○ https://goo.gl/6wcQKU
OR
○ https://github.com/itzpc/Introduction-To-Python-
Programming
7
Introduction To Python Programming /in/pcakhilnadh
Fork	the	Repository
Contents
○ Introduction
○ Conditional Statements
○ Operators
○ Data Types
○ Iterative Statements
○ Functions
○ Modules
○ Conclusion
8
Introduction To Python Programming /in/pcakhilnadh
Introduction
https://python.org
9
Introduction To Python Programming /in/pcakhilnadh
Installing	Python
Introduction
○ Linux
$ sudo apt-get update
$ sudo apt-get install python3
○ Mac OS
$ brew install python3
10
Introduction To Python Programming /in/pcakhilnadh
Installing	Python	– Command	Line
Introduction
11
Introduction To Python Programming /in/pcakhilnadh
Python	:	Interpreted	or	Compiled	?
12
Introduction To Python Programming /in/pcakhilnadh
Python	:	Interpreted	or	Compiled	?
Compiler
Pgm.c a.out
Interpreter
Output
13
Introduction To Python Programming /in/pcakhilnadh
Output
Python	:	Interpreted	or	Compiled	?
14
According to Official Documentation of Python
“ Python is considered as Interpreted Language ”
It's worth noting that languages are not interpreted or
compiled, but rather language implementations either
interpret or compile code.
Introduction To Python Programming /in/pcakhilnadh
Python	:	Interpreted	or	Compiled	?
Introduction
○ From Shell
○ From File
python3 filename.py
15
Introduction To Python Programming /in/pcakhilnadh
Ways	to	Run	a	Py File
Introduction
16
Introduction To Python Programming /in/pcakhilnadh
Introduction	to	Memory	Management
X=10
10 X
X=10
Y=X
10 X
Y
10
10
“	Everything	in	Python	is	an	Object	”
Other	Prog Lang	C/JAVA
17
Introduction To Python Programming /in/pcakhilnadh
Introduction	to	Memory	Management
X=11 Y
X
“	Python	is	Dynamically	Typed	Language ”
10
11
Z=10 Y
X
10
11
Z
What	Happens		X=11	?
Python		Optimizes	Memory
Introduction
18
Introduction To Python Programming /in/pcakhilnadh
Comparison	with	other	Languages
Introduction
19
Introduction To Python Programming /in/pcakhilnadh
Sample	Python	File
Syntax	Function	 Can	Pass	Arguments
Note	the	Space	.	
Indentation	– Technically	!
NO	semi	colon	?
Conditional
Statements
○ if statement
○ if else statement
○ Chained Conditional (~Switch)
○ Nested Conditional
20
Introduction To Python Programming /in/pcakhilnadh
21
if		statement
if BOOLEAN	EXPRESSION	:	
STATEMENTS
Syntax
Note	the	Space	.	
Indentation	– Technically	!
Note	the	colon
NO	semi	colon	!
Exercise 1
Run	this	code	snippet	.	To	Demonstrate	working	of	if	statement		
Introduction To Python Programming /in/pcakhilnadh
22
if	else	statement
if BOOLEAN	EXPRESSION	:	
STATEMENTS_1
else	:
STATEMENT_2
Syntax
Exercise 2
Run	this	code	snippet	.	To	Demonstrate	working	of	if	else	statement		
Introduction To Python Programming /in/pcakhilnadh
23
Chained	conditionals
if EXPRESSION:
STATEMENTS_A
elif EXPRESSION:
STATEMENTS_B
else:
STATEMENTS_C
Syntax
Exercise 3
Run	this	code	snippet	.	To	Demonstrate	working	of	chained	conditionals	
Introduction To Python Programming /in/pcakhilnadh
24
Nested	conditionals
if Expression :
STATEMENTS_A
else:
if Expression :
STATEMENTS_B
else:
STATEMENTS_C
Syntax
Introduction To Python Programming /in/pcakhilnadh
Operators
○ Arithmetic Operators
○ Comparison Operators
○ Bitwise Operators
○ Logical Operators
○ Membership Operator
25
Introduction To Python Programming /in/pcakhilnadh
26
Arithmetic	Operator
○ Addition +
○ Subtraction									-
○ Multiplication				*
○ Division /
○ Modulus	 %
○ Exponent											**
○ Floor	Division				//
Exercise 4
Make	a	Simple	Calculator	Program	.	Fill	this	code	snippet	and	pull	a	request	in	GitHub	
Introduction To Python Programming /in/pcakhilnadh
27
Comparision Operator
○ Equal to ==
○ Not	Equal	to							 !=
○ Greater	Than				 >
○ Less	Than <
○ Greater	than	Equal	to	>=
○ Less	than	Equal	to	 <=
Introduction To Python Programming /in/pcakhilnadh
28
Logical	Operator
○ Logical AND AND
○ Logical	OR					 OR
○ Logical	NOT	 NOT
Introduction To Python Programming /in/pcakhilnadh
Exercise 5
Let	x	be	a	two	digit	number.	Print	Grade	according	to	the	following	condition
x	>90	print	Eligible	for	Research	.	
x	between	70	and	90	print	Distinction
if	X	is	exactly	75	and	above	print	Eligible	for	Placement
if	X	is	less	than		70	print	Fail
Fill	this	code	snippet	and	pull	a	request	in	GitHub
29
Bitwise	Operator
○ Binary AND &
○ Binary OR |
○ Binary XOR ^
○ Binary Complement ~
○ Binary Left	Shift <<
○ Binary Right Shift >>
Introduction To Python Programming /in/pcakhilnadh
Exercise 6
Run	this	code	snippet	.	To	Demonstrate	working	of	Bitwise	Operator
30
Membership	Operator
○ in	
○ not	in
○ is
○ is	not
Introduction To Python Programming /in/pcakhilnadh
Data Types
○ None
○ Numbers
○ Sequences
○ Collection
○ Sets
○ File
31
Introduction To Python Programming /in/pcakhilnadh
32
None
○ Denote lack of value
a = None
Introduction To Python Programming /in/pcakhilnadh
33
Number
○ Boolean - immutable
○ Integers - immutable
○ Float - immutable
○ Long - immutable
○ Complex - immutable
Introduction To Python Programming /in/pcakhilnadh
34
Boolean
○ bool(expression) -> Convert the expression to Boolean value
○ bool(1) -> True
○ Following are considered False
○ False
○ None
○ Numeric Zero
○ Empty Sequences and Collections
Introduction To Python Programming /in/pcakhilnadh
35
Integers
○ int (number, base) -> Convert the string ‘number’ from ‘base’ to decimal value
○ base is optional if given ‘number’ must be of type <class string>
○ Python consider Integers as BigInt by default .
○ Can handle as many long integers as possible
○ a = int(70)
Introduction To Python Programming /in/pcakhilnadh
36
Float
○ Float (number) -> Convert the string or integer ‘number’ to float value
○ number can take
○ Sign. : ‘+’ or ‘-’
○ Infinity : ‘inf’ or ‘Infinity’
○ NaN : ‘nan’
○ a =float(‘ 1e-003’) -> 0.001
Introduction To Python Programming /in/pcakhilnadh
37
Complex
○ complex (real, imaginary) -> return complex number of form real + j imaginary
○ a = complex(1) -> 1+j 0
Introduction To Python Programming /in/pcakhilnadh
38
Sequences
○ String - immutable
○ Tuple - immutable
○ List. - mutable
Introduction To Python Programming /in/pcakhilnadh
39
String
Introduction To Python Programming /in/pcakhilnadh
○ Hold string type value
○ No char type in python
○ It also represent array of bytes (hold data from files)
○ a = str(object) -> Return a string containing a printable representation of an object
40
String
Introduction To Python Programming /in/pcakhilnadh
○ Str_object.split(separator,maxsplit)
“ab cd ef”.split() -> [‘ab’, ‘cd’, ‘ef’]
○ input() -> To read input from user
a = input(“ Enter a String ” )
○ “joinString”.join(sequence)
“-”.join([‘a’, ‘b’ ,‘c’ ,‘d’]). -> a-b-c-d
41
Tuple
Introduction To Python Programming /in/pcakhilnadh
○ Ordered and indexed collection of objects
○ Tuples of two or more items separated by comma
○ tuple(iterable). -> Convert an iterable into a tuple
○ Packing
my_tuple=tuple(3,4,’dog’)
○ Unpacking
a,b,c = my_tuple
42
List
○ Ordered and indexed collection of objects
○ Mutable
○ list(sequence) -> convert the objects into list
a=list(‘foo’) -> [‘f’, ‘o’, ‘o’]
○ List Indexing
Introduction To Python Programming /in/pcakhilnadh
Forward	Indexing
Backward	Indexing
a[0] -> 1
a[-1] ->5
43
List	Slicing
○ listObject[ <start> : <end> : <step> ]
a[1:3] -> 2 3 (Everything from 1 to 3 excluding the 3rd position)
a[1:] -> 2 3 4 5 (Everything from 1 to end)
Introduction To Python Programming /in/pcakhilnadh
Exercise 7
Read	string		from	user	and	store	it	in	list	.Sort	and	Reverse	the	list	
and	print	the	elements	in	the	even	position
Fill	this	code	snippet	and	pull	a	request	in	GitHub
Iterative
Statements
○ For loop
○ While loop
44
Introduction To Python Programming /in/pcakhilnadh
45
Collections
○ Dictionary
○ Set
○ Frozen Set
Introduction To Python Programming /in/pcakhilnadh
46
Dictionary
○ Mutable
○ Unordered Collection
○ Keys must be hashable and unique
○ List and Dict cannot act as keys
○ ~ Hash Table in other Languages
○ dict( iterable ) -> Returns a dictionary object
○ A= { 0: ‘a’,1: ‘b’, 2: ‘c’ }
Introduction To Python Programming /in/pcakhilnadh
47
For	Loops
○ Used for sequential traversal
○ Syntax
for iterator_variable in sequence:
statements(s)
○ It can be used to iterate over iterators and a range.
○ Sample Code Snippet
for i in range(10) :
print(i)
○ range(start, stop[, step])
Introduction To Python Programming /in/pcakhilnadh
It	is	sequence	or	List
48
While	Loop
○ Execute a block of statement as long as a given condition is true.
○ If condition is False . Come out of Loop
○ syntax
while (condition) :
statements
○ x = 0
while (x < 10) :
print(x)
x = x + 1
Introduction To Python Programming /in/pcakhilnadh
Functions
49
○ Function is a group of related statements that perform a specific task.
○ Variables inside function has local scope
○ Syntax
def function_name(parameters):
statement(s)
return
○ Function Call
function_name(parameters)
Introduction To Python Programming /in/pcakhilnadh
Optional
50
Functions
○ In Python, we can return multiple values from a function !!
def square(x,y):
return x**2, y**2
xsq, ysq = square(2,3)
Introduction To Python Programming /in/pcakhilnadh
Exercise 8
Read	a	number	from	user	and	find	factorial	using	recursive	
function
Fill	this	code	snippet	and	pull	a	request	in	GitHub
51
Lambda	Function
○ The small anonymous function
○ Take ‘n’ number of arguments but only one return type
○ Syntax
lambda arguments : expression
○ lambda function to add two numbers
add = lambda x,y : x+y
add(5,6)
○ s
Introduction To Python Programming /in/pcakhilnadh
52
Map	Function
○ Expects a function object and any number of iterables like list, dictionary, etc. It
executes the function_object for each element in the sequence and returns a list of
the elements modified by the function object
○ Syntax
map( functionObject , iterables )
○ Example
map( square, [2,3,4,5] ) -> 4,9,16, 25
○ Add two list values
○ list_a = [1, 2, 3]
list_b = [10, 20, 30]
map(lambda x, y: x + y, list_a, list_b)
# Output: [11, 22, 33]
Introduction To Python Programming /in/pcakhilnadh
53
Modules
○ A code library.
○ A file containing a set of functions you want to include in your application
○ To create a module just save the code you want in a file with the file extension .py
○ Example
save this as mymodule.py
def greeting(name):
print("Hello, " + name)
○ import and use the functions
import mymodule
mymodule.greeting("Jonathan")
○ import math
○ Import numpy
Introduction To Python Programming /in/pcakhilnadh
Conclusion
54
Introduction To Python Programming /in/pcakhilnadh
Thank You
Questions ?
55
Introduction To Python Programming
/in/pcakhilnadh
akhilnp.is.17@nitj.ac.in
/pcakhilnadh

More Related Content

What's hot (20)

Clojure basics
Clojure basics
Knoldus Inc.
 
Ch9c
Ch9c
kinnarshah8888
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
Jen Yee Hong
 
Basic c++ programs
Basic c++ programs
harman kaur
 
Algorithmic Notations
Algorithmic Notations
Muhammad Muzammal
 
A1 spyder variables_operators_nptel_pds1_sol
A1 spyder variables_operators_nptel_pds1_sol
malasumathi
 
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
Muhammad Ulhaque
 
GCC
GCC
Kir Chou
 
Operators and Control Statements in Python
Operators and Control Statements in Python
RajeswariA8
 
Algorithm and Programming (Record)
Algorithm and Programming (Record)
Adam Mukharil Bachtiar
 
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Adam Mukharil Bachtiar
 
Crange: Clang based tool to index and cross-reference C/C++ source code
Crange: Clang based tool to index and cross-reference C/C++ source code
Anurag Patel
 
Juan josefumeroarray14
Juan josefumeroarray14
Juan Fumero
 
Fpga 13-task-and-functions
Fpga 13-task-and-functions
Malik Tauqir Hasan
 
Algorithm analysis and design
Algorithm analysis and design
Megha V
 
Brief introduction to Algorithm analysis
Brief introduction to Algorithm analysis
Anantha Ramu
 
C++ Concepts and Ranges - How to use them?
C++ Concepts and Ranges - How to use them?
Mateusz Pusz
 
STL ALGORITHMS
STL ALGORITHMS
fawzmasood
 
Ch9a
Ch9a
kinnarshah8888
 
Clojure intro
Clojure intro
Basav Nagur
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
Jen Yee Hong
 
Basic c++ programs
Basic c++ programs
harman kaur
 
A1 spyder variables_operators_nptel_pds1_sol
A1 spyder variables_operators_nptel_pds1_sol
malasumathi
 
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
Muhammad Ulhaque
 
Operators and Control Statements in Python
Operators and Control Statements in Python
RajeswariA8
 
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Adam Mukharil Bachtiar
 
Crange: Clang based tool to index and cross-reference C/C++ source code
Crange: Clang based tool to index and cross-reference C/C++ source code
Anurag Patel
 
Juan josefumeroarray14
Juan josefumeroarray14
Juan Fumero
 
Algorithm analysis and design
Algorithm analysis and design
Megha V
 
Brief introduction to Algorithm analysis
Brief introduction to Algorithm analysis
Anantha Ramu
 
C++ Concepts and Ranges - How to use them?
C++ Concepts and Ranges - How to use them?
Mateusz Pusz
 
STL ALGORITHMS
STL ALGORITHMS
fawzmasood
 

Similar to Introduction to python programming [part 1] (20)

Python chapter presentation details.pptx
Python chapter presentation details.pptx
linatalole2001
 
4. Tools Proyek Data Science DTS-TA v.3.pptx
4. Tools Proyek Data Science DTS-TA v.3.pptx
irvaimuhammad
 
Introduction to python
Introduction to python
Rucha Gokhale
 
Meetup C++ A brief overview of c++17
Meetup C++ A brief overview of c++17
Daniel Eriksson
 
Chapter1 python introduction syntax general
Chapter1 python introduction syntax general
ssuser77162c
 
Python Programming by Dr B P Sharma for Everyone
Python Programming by Dr B P Sharma for Everyone
info560863
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
Zhen Wei
 
Python programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - Kalamassery
SHAMJITH KM
 
Python lecture 03
Python lecture 03
Tanwir Zaman
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
Towards hasktorch 1.0
Towards hasktorch 1.0
Junji Hashimoto
 
Pythonppt28 11-18
Pythonppt28 11-18
Saraswathi Murugan
 
FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
Saraswathi Murugan
 
Intro to Python for Non-Programmers
Intro to Python for Non-Programmers
Ahmad Alhour
 
Python Basics by Akanksha Bali
Python Basics by Akanksha Bali
Akanksha Bali
 
Data Structure and Algorithms (DSA) with Python
Data Structure and Algorithms (DSA) with Python
epsilonice
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
CP-Union
 
Python Workshop
Python Workshop
Saket Choudhary
 
Python chapter presentation details.pptx
Python chapter presentation details.pptx
linatalole2001
 
4. Tools Proyek Data Science DTS-TA v.3.pptx
4. Tools Proyek Data Science DTS-TA v.3.pptx
irvaimuhammad
 
Introduction to python
Introduction to python
Rucha Gokhale
 
Meetup C++ A brief overview of c++17
Meetup C++ A brief overview of c++17
Daniel Eriksson
 
Chapter1 python introduction syntax general
Chapter1 python introduction syntax general
ssuser77162c
 
Python Programming by Dr B P Sharma for Everyone
Python Programming by Dr B P Sharma for Everyone
info560863
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
Zhen Wei
 
Python programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - Kalamassery
SHAMJITH KM
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
Saraswathi Murugan
 
Intro to Python for Non-Programmers
Intro to Python for Non-Programmers
Ahmad Alhour
 
Python Basics by Akanksha Bali
Python Basics by Akanksha Bali
Akanksha Bali
 
Data Structure and Algorithms (DSA) with Python
Data Structure and Algorithms (DSA) with Python
epsilonice
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
CP-Union
 
Ad

More from Akhil Nadh PC (8)

Introduction to Computer basics for students
Introduction to Computer basics for students
Akhil Nadh PC
 
Cyber security awareness for students
Cyber security awareness for students
Akhil Nadh PC
 
High Secure Password Authentication System
High Secure Password Authentication System
Akhil Nadh PC
 
Blockchain Technology - A Systematic Study.
Blockchain Technology - A Systematic Study.
Akhil Nadh PC
 
Linux Basic Networking Command
Linux Basic Networking Command
Akhil Nadh PC
 
Introduction to Information Channel
Introduction to Information Channel
Akhil Nadh PC
 
Web Security and SSL - Secure Socket Layer
Web Security and SSL - Secure Socket Layer
Akhil Nadh PC
 
Chorus - Distributed Operating System [ case study ]
Chorus - Distributed Operating System [ case study ]
Akhil Nadh PC
 
Introduction to Computer basics for students
Introduction to Computer basics for students
Akhil Nadh PC
 
Cyber security awareness for students
Cyber security awareness for students
Akhil Nadh PC
 
High Secure Password Authentication System
High Secure Password Authentication System
Akhil Nadh PC
 
Blockchain Technology - A Systematic Study.
Blockchain Technology - A Systematic Study.
Akhil Nadh PC
 
Linux Basic Networking Command
Linux Basic Networking Command
Akhil Nadh PC
 
Introduction to Information Channel
Introduction to Information Channel
Akhil Nadh PC
 
Web Security and SSL - Secure Socket Layer
Web Security and SSL - Secure Socket Layer
Akhil Nadh PC
 
Chorus - Distributed Operating System [ case study ]
Chorus - Distributed Operating System [ case study ]
Akhil Nadh PC
 
Ad

Recently uploaded (20)

Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Himalayan Group of Professional Institutions (HGPI)
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
LDMMIA Spring Ending Guest Grad Student News
LDMMIA Spring Ending Guest Grad Student News
LDM & Mia eStudios
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
LDMMIA Spring Ending Guest Grad Student News
LDMMIA Spring Ending Guest Grad Student News
LDM & Mia eStudios
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 

Introduction to python programming [part 1]

  • 7. Before We Get Started ○ https://goo.gl/6wcQKU OR ○ https://github.com/itzpc/Introduction-To-Python- Programming 7 Introduction To Python Programming /in/pcakhilnadh Fork the Repository
  • 8. Contents ○ Introduction ○ Conditional Statements ○ Operators ○ Data Types ○ Iterative Statements ○ Functions ○ Modules ○ Conclusion 8 Introduction To Python Programming /in/pcakhilnadh
  • 10. Introduction ○ Linux $ sudo apt-get update $ sudo apt-get install python3 ○ Mac OS $ brew install python3 10 Introduction To Python Programming /in/pcakhilnadh Installing Python – Command Line
  • 11. Introduction 11 Introduction To Python Programming /in/pcakhilnadh Python : Interpreted or Compiled ?
  • 12. 12 Introduction To Python Programming /in/pcakhilnadh Python : Interpreted or Compiled ? Compiler Pgm.c a.out Interpreter Output
  • 13. 13 Introduction To Python Programming /in/pcakhilnadh Output Python : Interpreted or Compiled ?
  • 14. 14 According to Official Documentation of Python “ Python is considered as Interpreted Language ” It's worth noting that languages are not interpreted or compiled, but rather language implementations either interpret or compile code. Introduction To Python Programming /in/pcakhilnadh Python : Interpreted or Compiled ?
  • 15. Introduction ○ From Shell ○ From File python3 filename.py 15 Introduction To Python Programming /in/pcakhilnadh Ways to Run a Py File
  • 16. Introduction 16 Introduction To Python Programming /in/pcakhilnadh Introduction to Memory Management X=10 10 X X=10 Y=X 10 X Y 10 10 “ Everything in Python is an Object ” Other Prog Lang C/JAVA
  • 17. 17 Introduction To Python Programming /in/pcakhilnadh Introduction to Memory Management X=11 Y X “ Python is Dynamically Typed Language ” 10 11 Z=10 Y X 10 11 Z What Happens X=11 ? Python Optimizes Memory
  • 18. Introduction 18 Introduction To Python Programming /in/pcakhilnadh Comparison with other Languages
  • 19. Introduction 19 Introduction To Python Programming /in/pcakhilnadh Sample Python File Syntax Function Can Pass Arguments Note the Space . Indentation – Technically ! NO semi colon ?
  • 20. Conditional Statements ○ if statement ○ if else statement ○ Chained Conditional (~Switch) ○ Nested Conditional 20 Introduction To Python Programming /in/pcakhilnadh
  • 21. 21 if statement if BOOLEAN EXPRESSION : STATEMENTS Syntax Note the Space . Indentation – Technically ! Note the colon NO semi colon ! Exercise 1 Run this code snippet . To Demonstrate working of if statement Introduction To Python Programming /in/pcakhilnadh
  • 23. 23 Chained conditionals if EXPRESSION: STATEMENTS_A elif EXPRESSION: STATEMENTS_B else: STATEMENTS_C Syntax Exercise 3 Run this code snippet . To Demonstrate working of chained conditionals Introduction To Python Programming /in/pcakhilnadh
  • 24. 24 Nested conditionals if Expression : STATEMENTS_A else: if Expression : STATEMENTS_B else: STATEMENTS_C Syntax Introduction To Python Programming /in/pcakhilnadh
  • 25. Operators ○ Arithmetic Operators ○ Comparison Operators ○ Bitwise Operators ○ Logical Operators ○ Membership Operator 25 Introduction To Python Programming /in/pcakhilnadh
  • 26. 26 Arithmetic Operator ○ Addition + ○ Subtraction - ○ Multiplication * ○ Division / ○ Modulus % ○ Exponent ** ○ Floor Division // Exercise 4 Make a Simple Calculator Program . Fill this code snippet and pull a request in GitHub Introduction To Python Programming /in/pcakhilnadh
  • 27. 27 Comparision Operator ○ Equal to == ○ Not Equal to != ○ Greater Than > ○ Less Than < ○ Greater than Equal to >= ○ Less than Equal to <= Introduction To Python Programming /in/pcakhilnadh
  • 28. 28 Logical Operator ○ Logical AND AND ○ Logical OR OR ○ Logical NOT NOT Introduction To Python Programming /in/pcakhilnadh Exercise 5 Let x be a two digit number. Print Grade according to the following condition x >90 print Eligible for Research . x between 70 and 90 print Distinction if X is exactly 75 and above print Eligible for Placement if X is less than 70 print Fail Fill this code snippet and pull a request in GitHub
  • 29. 29 Bitwise Operator ○ Binary AND & ○ Binary OR | ○ Binary XOR ^ ○ Binary Complement ~ ○ Binary Left Shift << ○ Binary Right Shift >> Introduction To Python Programming /in/pcakhilnadh Exercise 6 Run this code snippet . To Demonstrate working of Bitwise Operator
  • 30. 30 Membership Operator ○ in ○ not in ○ is ○ is not Introduction To Python Programming /in/pcakhilnadh
  • 31. Data Types ○ None ○ Numbers ○ Sequences ○ Collection ○ Sets ○ File 31 Introduction To Python Programming /in/pcakhilnadh
  • 32. 32 None ○ Denote lack of value a = None Introduction To Python Programming /in/pcakhilnadh
  • 33. 33 Number ○ Boolean - immutable ○ Integers - immutable ○ Float - immutable ○ Long - immutable ○ Complex - immutable Introduction To Python Programming /in/pcakhilnadh
  • 34. 34 Boolean ○ bool(expression) -> Convert the expression to Boolean value ○ bool(1) -> True ○ Following are considered False ○ False ○ None ○ Numeric Zero ○ Empty Sequences and Collections Introduction To Python Programming /in/pcakhilnadh
  • 35. 35 Integers ○ int (number, base) -> Convert the string ‘number’ from ‘base’ to decimal value ○ base is optional if given ‘number’ must be of type <class string> ○ Python consider Integers as BigInt by default . ○ Can handle as many long integers as possible ○ a = int(70) Introduction To Python Programming /in/pcakhilnadh
  • 36. 36 Float ○ Float (number) -> Convert the string or integer ‘number’ to float value ○ number can take ○ Sign. : ‘+’ or ‘-’ ○ Infinity : ‘inf’ or ‘Infinity’ ○ NaN : ‘nan’ ○ a =float(‘ 1e-003’) -> 0.001 Introduction To Python Programming /in/pcakhilnadh
  • 37. 37 Complex ○ complex (real, imaginary) -> return complex number of form real + j imaginary ○ a = complex(1) -> 1+j 0 Introduction To Python Programming /in/pcakhilnadh
  • 38. 38 Sequences ○ String - immutable ○ Tuple - immutable ○ List. - mutable Introduction To Python Programming /in/pcakhilnadh
  • 39. 39 String Introduction To Python Programming /in/pcakhilnadh ○ Hold string type value ○ No char type in python ○ It also represent array of bytes (hold data from files) ○ a = str(object) -> Return a string containing a printable representation of an object
  • 40. 40 String Introduction To Python Programming /in/pcakhilnadh ○ Str_object.split(separator,maxsplit) “ab cd ef”.split() -> [‘ab’, ‘cd’, ‘ef’] ○ input() -> To read input from user a = input(“ Enter a String ” ) ○ “joinString”.join(sequence) “-”.join([‘a’, ‘b’ ,‘c’ ,‘d’]). -> a-b-c-d
  • 41. 41 Tuple Introduction To Python Programming /in/pcakhilnadh ○ Ordered and indexed collection of objects ○ Tuples of two or more items separated by comma ○ tuple(iterable). -> Convert an iterable into a tuple ○ Packing my_tuple=tuple(3,4,’dog’) ○ Unpacking a,b,c = my_tuple
  • 42. 42 List ○ Ordered and indexed collection of objects ○ Mutable ○ list(sequence) -> convert the objects into list a=list(‘foo’) -> [‘f’, ‘o’, ‘o’] ○ List Indexing Introduction To Python Programming /in/pcakhilnadh Forward Indexing Backward Indexing a[0] -> 1 a[-1] ->5
  • 43. 43 List Slicing ○ listObject[ <start> : <end> : <step> ] a[1:3] -> 2 3 (Everything from 1 to 3 excluding the 3rd position) a[1:] -> 2 3 4 5 (Everything from 1 to end) Introduction To Python Programming /in/pcakhilnadh Exercise 7 Read string from user and store it in list .Sort and Reverse the list and print the elements in the even position Fill this code snippet and pull a request in GitHub
  • 44. Iterative Statements ○ For loop ○ While loop 44 Introduction To Python Programming /in/pcakhilnadh
  • 45. 45 Collections ○ Dictionary ○ Set ○ Frozen Set Introduction To Python Programming /in/pcakhilnadh
  • 46. 46 Dictionary ○ Mutable ○ Unordered Collection ○ Keys must be hashable and unique ○ List and Dict cannot act as keys ○ ~ Hash Table in other Languages ○ dict( iterable ) -> Returns a dictionary object ○ A= { 0: ‘a’,1: ‘b’, 2: ‘c’ } Introduction To Python Programming /in/pcakhilnadh
  • 47. 47 For Loops ○ Used for sequential traversal ○ Syntax for iterator_variable in sequence: statements(s) ○ It can be used to iterate over iterators and a range. ○ Sample Code Snippet for i in range(10) : print(i) ○ range(start, stop[, step]) Introduction To Python Programming /in/pcakhilnadh It is sequence or List
  • 48. 48 While Loop ○ Execute a block of statement as long as a given condition is true. ○ If condition is False . Come out of Loop ○ syntax while (condition) : statements ○ x = 0 while (x < 10) : print(x) x = x + 1 Introduction To Python Programming /in/pcakhilnadh
  • 49. Functions 49 ○ Function is a group of related statements that perform a specific task. ○ Variables inside function has local scope ○ Syntax def function_name(parameters): statement(s) return ○ Function Call function_name(parameters) Introduction To Python Programming /in/pcakhilnadh Optional
  • 50. 50 Functions ○ In Python, we can return multiple values from a function !! def square(x,y): return x**2, y**2 xsq, ysq = square(2,3) Introduction To Python Programming /in/pcakhilnadh Exercise 8 Read a number from user and find factorial using recursive function Fill this code snippet and pull a request in GitHub
  • 51. 51 Lambda Function ○ The small anonymous function ○ Take ‘n’ number of arguments but only one return type ○ Syntax lambda arguments : expression ○ lambda function to add two numbers add = lambda x,y : x+y add(5,6) ○ s Introduction To Python Programming /in/pcakhilnadh
  • 52. 52 Map Function ○ Expects a function object and any number of iterables like list, dictionary, etc. It executes the function_object for each element in the sequence and returns a list of the elements modified by the function object ○ Syntax map( functionObject , iterables ) ○ Example map( square, [2,3,4,5] ) -> 4,9,16, 25 ○ Add two list values ○ list_a = [1, 2, 3] list_b = [10, 20, 30] map(lambda x, y: x + y, list_a, list_b) # Output: [11, 22, 33] Introduction To Python Programming /in/pcakhilnadh
  • 53. 53 Modules ○ A code library. ○ A file containing a set of functions you want to include in your application ○ To create a module just save the code you want in a file with the file extension .py ○ Example save this as mymodule.py def greeting(name): print("Hello, " + name) ○ import and use the functions import mymodule mymodule.greeting("Jonathan") ○ import math ○ Import numpy Introduction To Python Programming /in/pcakhilnadh
  • 54. Conclusion 54 Introduction To Python Programming /in/pcakhilnadh
  • 55. Thank You Questions ? 55 Introduction To Python Programming /in/pcakhilnadh [email protected] /pcakhilnadh