SlideShare a Scribd company logo
1 of 55
Download to read offline
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

2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - englishJen Yee Hong
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programsharman kaur
 
A1 spyder variables_operators_nptel_pds1_sol
A1 spyder variables_operators_nptel_pds1_solA1 spyder variables_operators_nptel_pds1_sol
A1 spyder variables_operators_nptel_pds1_solmalasumathi
 
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...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 PythonOperators and Control Statements in Python
Operators and Control Statements in PythonRajeswariA8
 
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...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 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 josefumeroarray14Juan josefumeroarray14
Juan josefumeroarray14Juan Fumero
 
Algorithm analysis and design
Algorithm analysis and designAlgorithm analysis and design
Algorithm analysis and designMegha V
 
Brief introduction to Algorithm analysis
Brief introduction to Algorithm analysis 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?C++ Concepts and Ranges - How to use them?
C++ Concepts and Ranges - How to use them?Mateusz Pusz
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMSfawzmasood
 

What's hot (20)

Clojure basics
Clojure basicsClojure basics
Clojure basics
 
Ch9c
Ch9cCh9c
Ch9c
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
 
Algorithmic Notations
Algorithmic NotationsAlgorithmic Notations
Algorithmic Notations
 
A1 spyder variables_operators_nptel_pds1_sol
A1 spyder variables_operators_nptel_pds1_solA1 spyder variables_operators_nptel_pds1_sol
A1 spyder variables_operators_nptel_pds1_sol
 
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
 
GCC
GCCGCC
GCC
 
Operators and Control Statements in Python
Operators and Control Statements in PythonOperators and Control Statements in Python
Operators and Control Statements in Python
 
Algorithm and Programming (Record)
Algorithm and Programming (Record)Algorithm and Programming (Record)
Algorithm and Programming (Record)
 
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
 
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 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
 
Juan josefumeroarray14
Juan josefumeroarray14Juan josefumeroarray14
Juan josefumeroarray14
 
Fpga 13-task-and-functions
Fpga 13-task-and-functionsFpga 13-task-and-functions
Fpga 13-task-and-functions
 
Algorithm analysis and design
Algorithm analysis and designAlgorithm analysis and design
Algorithm analysis and design
 
Brief introduction to Algorithm analysis
Brief introduction to Algorithm analysis Brief introduction to Algorithm analysis
Brief introduction to Algorithm analysis
 
C++ Concepts and Ranges - How to use them?
C++ Concepts and Ranges - How to use them?C++ Concepts and Ranges - How to use them?
C++ Concepts and Ranges - How to use them?
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
 
Ch9a
Ch9aCh9a
Ch9a
 
Clojure intro
Clojure introClojure intro
Clojure intro
 

Similar to Introduction to python programming [part 1]

Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonRucha Gokhale
 
Meetup C++ A brief overview of c++17
Meetup C++  A brief overview of c++17Meetup C++  A brief overview of c++17
Meetup C++ A brief overview of c++17Daniel Eriksson
 
Python Programming by Dr B P Sharma for Everyone
Python Programming by Dr B P Sharma for  EveryonePython Programming by Dr B P Sharma for  Everyone
Python Programming by Dr B P Sharma for Everyoneinfo560863
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.supriyasarkar38
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu WorksZhen Wei
 
Python programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - KalamasseryPython programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - KalamasserySHAMJITH KM
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CSteffen Wenz
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE Saraswathi Murugan
 
Intro to Python for Non-Programmers
Intro to Python for Non-ProgrammersIntro to Python for Non-Programmers
Intro to Python for Non-ProgrammersAhmad Alhour
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha BaliAkanksha Bali
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonCP-Union
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoMuhammad Abdullah
 
Develop Embedded Software Module-Session 3
Develop Embedded Software Module-Session 3Develop Embedded Software Module-Session 3
Develop Embedded Software Module-Session 3Naveen Kumar
 
Python bible
Python biblePython bible
Python bibleadarsh j
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Edureka!
 
Introduction to python & its applications.ppt
Introduction to python & its applications.pptIntroduction to python & its applications.ppt
Introduction to python & its applications.pptPradeepNB2
 

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

Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Meetup C++ A brief overview of c++17
Meetup C++  A brief overview of c++17Meetup C++  A brief overview of c++17
Meetup C++ A brief overview of c++17
 
Python Programming by Dr B P Sharma for Everyone
Python Programming by Dr B P Sharma for  EveryonePython Programming by Dr B P Sharma for  Everyone
Python Programming by Dr B P Sharma for Everyone
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
 
Python programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - KalamasseryPython programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - Kalamassery
 
Python lecture 03
Python lecture 03Python lecture 03
Python lecture 03
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Towards hasktorch 1.0
Towards hasktorch 1.0Towards hasktorch 1.0
Towards hasktorch 1.0
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
 
Intro to Python for Non-Programmers
Intro to Python for Non-ProgrammersIntro to Python for Non-Programmers
Intro to Python for Non-Programmers
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
 
Python Workshop
Python WorkshopPython Workshop
Python Workshop
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demo
 
Develop Embedded Software Module-Session 3
Develop Embedded Software Module-Session 3Develop Embedded Software Module-Session 3
Develop Embedded Software Module-Session 3
 
Python bible
Python biblePython bible
Python bible
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
 
Introduction to python & its applications.ppt
Introduction to python & its applications.pptIntroduction to python & its applications.ppt
Introduction to python & its applications.ppt
 

More from Akhil Nadh PC

Introduction to Computer basics for students
Introduction to Computer basics for studentsIntroduction to Computer basics for students
Introduction to Computer basics for studentsAkhil Nadh PC
 
Cyber security awareness for students
 Cyber security awareness for students Cyber security awareness for students
Cyber security awareness for studentsAkhil Nadh PC
 
High Secure Password Authentication System
High Secure Password Authentication SystemHigh Secure Password Authentication System
High Secure Password Authentication SystemAkhil Nadh PC
 
Blockchain Technology - A Systematic Study.
Blockchain Technology - A Systematic Study.Blockchain Technology - A Systematic Study.
Blockchain Technology - A Systematic Study.Akhil Nadh PC
 
Linux Basic Networking Command
Linux Basic Networking CommandLinux Basic Networking Command
Linux Basic Networking CommandAkhil Nadh PC
 
Introduction to Information Channel
Introduction to Information ChannelIntroduction to Information Channel
Introduction to Information ChannelAkhil Nadh PC
 
Web Security and SSL - Secure Socket Layer
Web Security and SSL - Secure Socket LayerWeb Security and SSL - Secure Socket Layer
Web Security and SSL - Secure Socket LayerAkhil Nadh PC
 
Chorus - Distributed Operating System [ case study ]
Chorus - Distributed Operating System [ case study ]Chorus - Distributed Operating System [ case study ]
Chorus - Distributed Operating System [ case study ]Akhil Nadh PC
 

More from Akhil Nadh PC (8)

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

Recently uploaded

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 

Recently uploaded (20)

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 

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
  • 9. Introduction https://python.org 9 Introduction To Python Programming /in/pcakhilnadh Installing Python
  • 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 akhilnp.is.17@nitj.ac.in /pcakhilnadh