SlideShare a Scribd company logo
1 of 44
Chapter - 3
Python programming
fundamentals
Introduction
A Python program is called a script.
Script is a sequence of definitions and commands.
These commands are executed by Python interpreter
known as PYTHON SHELL.
In python programming,
 data types are inbuilt hence support “dynamic
typing”
 declaration of variables is not required.
 memory management is automatically done.
Variables
A variable is like a container that stores values that you
can access or change.
A variable has three main components:
a)Identity of variable
b)Type of variable
c)Value of variable
Variables
a) Identity of the variable
It refers to object’s address in the memory.
>>> x=10
e.g. >>> id (x)
Data Type
b) Type of the variable
Type means data type of a variable.
1. Number: It stores numerical values.
Python supports three built in numeric
types – integer,
floating point numbers and
complex numbers.
Data Type
a. int (integer): Integer represents whole
numbers. (positive or negative)
e.g. -6, 0, 23466
b. float (floating point numbers): It
represents numbers with decimal
point.
e.g. -43.2, 6.0
c. Complex numbers: It is made up of pair
of real and imaginary number.
e.g. 2+5j
Data Type
2. String (str): It is a sequence of
characters. (combination of letters,
numbers and symbols).
It is enclosed within single or double
quotes.
e.g. (‘ ’ or “ ”)
>>> rem= “Hello Welcome to Python”
>>> print (rem)
Hello Welcome to Python
Data Type
3. Boolean (bool): It represents one of the
two possible values – True or False.
>>> bool_1 = (6>10)
>>> print (bool_1)
False
>>> bool_2 = (6<10)
>>> print (bool_2)
True
Data Type
4. None: It is a special data type with single
value.
It is used to signify absence of value
evaluating to false in a situation.
>>> value_1 = None
>>> print (value_1)
None
type() – if you wish to determine type of the
variable.
e.g.
>>> type(10)
<class ‘int’>
>>> type(8.2)
<class ‘float’>
>>> type(“hello”)
<class ‘str’>
>>> type(True)
<class ‘bool’>
Data Type
Value
c) Value of variable
Values are assigned to a variable using
assignment operator (=)..
e.g.
>>>marks=87
>>>print(marks)
87
marks – Name of the variable
Value of the variable
87
Value
The concept of assignment:
There should be only one variable on the left-hand side of
assignment operator.
This variable is called Left value or L-value
There can be any valid expression on the right-hand side of
assignment operator.
This variable is called Right value or R-value
L-value = R-value
Value_1 = 100
Variable Assignment
operator
Value
Value
Multiple assignments:
We can declare multiple variables in a
single statement.
e.g.
>>>x, y, z, p = 2, 40, 30.5, ‘Vinay’
Variable Naming Convention
1. A variable name can contain letter, digits and underscore (_). No
other characters are allowed.
2. A variable name must start with an alphabet or and underscore (_).
3. A variable name cannot contain spaces.
4. Keyword cannot be used as a variable name.
5. Variable names are case sensitive. Num and num are different.
6. Variable names should be short and meaningful.
Invalid variable names – 3dgraph, roll#no, first name, d.o.b, while
Input/Output
Python provides three functions for getting
user’s input.
1. input() function– It is used to get data in
script mode.
The input() function takes string as an
argument.
It always returns a value of string type.
Input/Output
2. int() function– It is used to convert input string
value to numeric value.
3. float() function – It converts fetched value in float
type.
4. eval() – This function is used to evaluate the value
of a string.
It takes input as string and evaluates this string as
number and return numeric result.
NOTE : input() function always enter string value in
python 3. So on need int(), float() function can be
used for data conversion.
Sample Program
n1 = input("Enter first number")
n2 = input("Enter second number")
Sum=n1+n2
print("Sum is:", Sum)
Sample Program
n1 = eval(input("Enter first number"))
n2 = eval(input("Enter second number"))
Sum=n1+n2
print("Sum is:", Sum)
n1 = int(input("Enter first number"))
n2 = int(input("Enter second number"))
Sum=n1+n2
print("Sum is:", Sum)
Sample Program
n1 = eval(input("Enter first number"))
n2 = eval(input("Enter second number"))
Sum=n1+n2
print("Sum is:", Sum)
n1 = int(input("Enter first number"))
n2 = int(input("Enter second number"))
Sum=n1+n2
print("Sum is:", Sum)
To calculate simple interest
p = int(input("Enter Principal:"))
r = float(input("Enter Rate:"))
t = int(input("Enter Time:"))
si=0.0
si=(p*r*t)/100
print("Simple Interest is:", si)
m1 = int(input("Enter marks in English:"))
m2 = int(input("Enter marks in Hindi:"))
m3 = int(input("Enter marks in Maths:"))
m4 = int(input("Enter marks in Science:"))
m5 = int(input("Enter marks in Social Science:"))
total=m1+m2+m3+m4+m5
per = total/5
print("Total is:", total)
print("Percenatge is:", per)
To calculate total and percentage
Python Character Set
A set of valid characters recognized by python.
• Python uses the traditional ASCII character set.
• The latest version recognizes the Unicode character set.
The ASCII character set is a subset of the Unicode
character set.
Letters: a-z, A-Z
Digits : 0-9
Special symbols : Special symbol available over keyboard
White spaces: blank space, tab, carriage return, new
line, form feed
Other characters: Unicode
Tokens
Smallest individual unit in a program is
known as token.
1. Keywords
2. Identifiers
3. Literals
4. Operators
5. Delimiters
1. Keywords
Reserved word of the compiler/interpreter which can’t
be used as identifier.
2. Identifiers
A Python identifier is a name used to
identify a variable, function, class,
module or other object.
3. Literals
Literals in Python can be defined as number,
text, or other data that represent values to be
stored in variables.
Example of String Literals in Python
name = ‘Johni’ , fname=“johny”
Example of Integer Literals in Python(numeric literal)
age = 22
Example of Float Literals in Python(numeric literal)
height = 6.2
Example of Special Literals in Python
name = None
3. Literals
Escape sequence
e.g.
print(“I am a student of n APS t Yol Cantt”)
4. Operators
Operators can be defined as symbols that are used to
perform operations on operands.
Types of Operators
a. Arithmetic Operators.
b. Relational Operators.
c. Assignment Operators.
d. Logical Operators.
e. Membership Operators
f. Identity Operators
4. Operators
a. Arithmetic Operators.
Arithmetic Operators are used to perform arithmetic
operations like addition, multiplication, division etc.
print ("hello"+"python")
print(2+3)
print(10-3)
print(22%5)
print(19//5)
print(2**3)
Output:
hellopython
5
7
2
3
8
4. Operators
b. Relational Operators.
Relational Operators are used to compare the values.
print(5==3) False
print(7>3) True
print(15<7) False
print(3!=2) True
print(7>=8) False
print(3<=4) True
4. Operators
c. Assignment Operators.
Used to assign values to the variables.
a=10
print(a)
a+=9
print(a)
b=11
b*=3
print(b)
c=19
c/=2
print(c)
d=2
d**=4
print(d)
Output:
10
19
33
9.5
16
4. Operators
d. Logical Operators.
Logical Operators are used to perform logical operations
on the given two variables or values.
a=30
b=20
if(a==30 and b==20):
print("hello")
Output :-
hello
a=70
b=20
if(a==30 or b==20):
print("hello")
4. Operators
e. Membership Operators
It used to validate whether a value is found within a
sequence such as such as strings, lists, or tuples.
E.g.
a = 22
list = [11, 22,33,44]
ans= a in list
print(ans)
Output: True
E.g.
a = 22
list = [11, 22,33,44]
ans= a not in list
print(ans)
Output: False
4. Operators
f. Identity Operators
Identity operators in Python compare the memory
locations of two objects.
5. Delimiters
These are the symbols which can be used as
separator of values or to enclose some values.
e.g ( ) { } [ ] , ; :
Token Category
X Variable
y Variable
z Variable
print Keyword
( ) Delimiter
/ Operator
68 Literal
“x, y, z” Literal
Comments
Comments are statements in the script that are
ignored by the Python interpreter.
Comments (hash symbol = #) makes code more
readable and understandable.
# Program to assign value
x=10
x=x+100 # increase value of x by 100
print(x)
Expressions
Expressions are combination of value(s). i.e.
constant, variable and operators.
Expression Value
5+2*4 13
8+12*2-4 28
Converting mathematical expression to
equivalent Python expression
Algebraic Expression Python Expression
y = 3 (
𝑥
2
) y = 3 * x / 2
z= 3bc + 4 z = 3*b*c + 4
User Defined Functions
A function is a group of statements that exists
within a program for the purpose of performing a
specific task.
Syntax:
def function_name(comma_sep_list_parameters):
statements
User Defined Functions
Example 1:
def display():
print(“Welcome to pyhton”)
>>>display()
Example 2:
def arearec(len, wd):
area=len*wd
return area
>>>arearec(30, 10)

More Related Content

Similar to IMP PPT- Python programming fundamentals.pptx

Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniquesvalarpink
 
Introduction to C Programming - R.D.Sivakumar
Introduction to C Programming -  R.D.SivakumarIntroduction to C Programming -  R.D.Sivakumar
Introduction to C Programming - R.D.SivakumarSivakumar R D .
 
009 Data Handling .pptx
009 Data Handling .pptx009 Data Handling .pptx
009 Data Handling .pptxssuser6c66f3
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III TermAndrew Raj
 
what-is-python-presentation.pptx
what-is-python-presentation.pptxwhat-is-python-presentation.pptx
what-is-python-presentation.pptxVijay Krishna
 
What is Paython.pptx
What is Paython.pptxWhat is Paython.pptx
What is Paython.pptxParag Soni
 
Data types in python
Data types in pythonData types in python
Data types in pythonRaginiJain21
 
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxCS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxfaithxdunce63732
 
python-presentation.pptx
python-presentation.pptxpython-presentation.pptx
python-presentation.pptxVijay Krishna
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python FundamentalsPraveen M Jigajinni
 
uom-2552-what-is-python-presentation.pptx
uom-2552-what-is-python-presentation.pptxuom-2552-what-is-python-presentation.pptx
uom-2552-what-is-python-presentation.pptxChetanChauhan203001
 
uom-2552-what-is-python-presentation (1).pptx
uom-2552-what-is-python-presentation (1).pptxuom-2552-what-is-python-presentation (1).pptx
uom-2552-what-is-python-presentation (1).pptxPrabha Karan
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in PythonMSB Academy
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in PythonRaajendra M
 

Similar to IMP PPT- Python programming fundamentals.pptx (20)

Python basics
Python basicsPython basics
Python basics
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
Python programming
Python  programmingPython  programming
Python programming
 
Introduction to C Programming - R.D.Sivakumar
Introduction to C Programming -  R.D.SivakumarIntroduction to C Programming -  R.D.Sivakumar
Introduction to C Programming - R.D.Sivakumar
 
009 Data Handling .pptx
009 Data Handling .pptx009 Data Handling .pptx
009 Data Handling .pptx
 
Python numbers
Python numbersPython numbers
Python numbers
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
 
what-is-python-presentation.pptx
what-is-python-presentation.pptxwhat-is-python-presentation.pptx
what-is-python-presentation.pptx
 
What is Paython.pptx
What is Paython.pptxWhat is Paython.pptx
What is Paython.pptx
 
Data types in python
Data types in pythonData types in python
Data types in python
 
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxCS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
 
python-presentation.pptx
python-presentation.pptxpython-presentation.pptx
python-presentation.pptx
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
 
uom-2552-what-is-python-presentation.pptx
uom-2552-what-is-python-presentation.pptxuom-2552-what-is-python-presentation.pptx
uom-2552-what-is-python-presentation.pptx
 
uom-2552-what-is-python-presentation (1).pptx
uom-2552-what-is-python-presentation (1).pptxuom-2552-what-is-python-presentation (1).pptx
uom-2552-what-is-python-presentation (1).pptx
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
 
python
pythonpython
python
 

Recently uploaded

VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...Suhani Kapoor
 
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...Suhani Kapoor
 
Storytelling, Ethics and Workflow in Documentary Photography
Storytelling, Ethics and Workflow in Documentary PhotographyStorytelling, Ethics and Workflow in Documentary Photography
Storytelling, Ethics and Workflow in Documentary PhotographyOrtega Alikwe
 
Call Girl in Low Price Delhi Punjabi Bagh 9711199012
Call Girl in Low Price Delhi Punjabi Bagh  9711199012Call Girl in Low Price Delhi Punjabi Bagh  9711199012
Call Girl in Low Price Delhi Punjabi Bagh 9711199012sapnasaifi408
 
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一2s3dgmej
 
Dubai Call Girls Naija O525547819 Call Girls In Dubai Home Made
Dubai Call Girls Naija O525547819 Call Girls In Dubai Home MadeDubai Call Girls Naija O525547819 Call Girls In Dubai Home Made
Dubai Call Girls Naija O525547819 Call Girls In Dubai Home Madekojalkojal131
 
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一A SSS
 
Black and White Minimalist Co Letter.pdf
Black and White Minimalist Co Letter.pdfBlack and White Minimalist Co Letter.pdf
Black and White Minimalist Co Letter.pdfpadillaangelina0023
 
办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一
办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一
办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一A SSS
 
加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位
加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位
加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位obuhobo
 
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...Suhani Kapoor
 
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...shivangimorya083
 
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士obuhobo
 
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...Suhani Kapoor
 
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证nhjeo1gg
 
(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...
(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...
(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...gurkirankumar98700
 
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call GirlsDelhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girlsshivangimorya083
 
NPPE STUDY GUIDE - NOV2021_study_104040.pdf
NPPE STUDY GUIDE - NOV2021_study_104040.pdfNPPE STUDY GUIDE - NOV2021_study_104040.pdf
NPPE STUDY GUIDE - NOV2021_study_104040.pdfDivyeshPatel234692
 
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一Fs
 

Recently uploaded (20)

VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
 
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
 
Storytelling, Ethics and Workflow in Documentary Photography
Storytelling, Ethics and Workflow in Documentary PhotographyStorytelling, Ethics and Workflow in Documentary Photography
Storytelling, Ethics and Workflow in Documentary Photography
 
Call Girl in Low Price Delhi Punjabi Bagh 9711199012
Call Girl in Low Price Delhi Punjabi Bagh  9711199012Call Girl in Low Price Delhi Punjabi Bagh  9711199012
Call Girl in Low Price Delhi Punjabi Bagh 9711199012
 
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
 
Dubai Call Girls Naija O525547819 Call Girls In Dubai Home Made
Dubai Call Girls Naija O525547819 Call Girls In Dubai Home MadeDubai Call Girls Naija O525547819 Call Girls In Dubai Home Made
Dubai Call Girls Naija O525547819 Call Girls In Dubai Home Made
 
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
 
Black and White Minimalist Co Letter.pdf
Black and White Minimalist Co Letter.pdfBlack and White Minimalist Co Letter.pdf
Black and White Minimalist Co Letter.pdf
 
办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一
办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一
办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一
 
加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位
加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位
加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位
 
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
 
FULL ENJOY Call Girls In Gautam Nagar (Delhi) Call Us 9953056974
FULL ENJOY Call Girls In Gautam Nagar (Delhi) Call Us 9953056974FULL ENJOY Call Girls In Gautam Nagar (Delhi) Call Us 9953056974
FULL ENJOY Call Girls In Gautam Nagar (Delhi) Call Us 9953056974
 
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
 
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
 
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
 
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
 
(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...
(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...
(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...
 
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call GirlsDelhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
 
NPPE STUDY GUIDE - NOV2021_study_104040.pdf
NPPE STUDY GUIDE - NOV2021_study_104040.pdfNPPE STUDY GUIDE - NOV2021_study_104040.pdf
NPPE STUDY GUIDE - NOV2021_study_104040.pdf
 
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
 

IMP PPT- Python programming fundamentals.pptx

  • 1. Chapter - 3 Python programming fundamentals
  • 2. Introduction A Python program is called a script. Script is a sequence of definitions and commands. These commands are executed by Python interpreter known as PYTHON SHELL. In python programming,  data types are inbuilt hence support “dynamic typing”  declaration of variables is not required.  memory management is automatically done.
  • 3. Variables A variable is like a container that stores values that you can access or change. A variable has three main components: a)Identity of variable b)Type of variable c)Value of variable
  • 4. Variables a) Identity of the variable It refers to object’s address in the memory. >>> x=10 e.g. >>> id (x)
  • 5. Data Type b) Type of the variable Type means data type of a variable. 1. Number: It stores numerical values. Python supports three built in numeric types – integer, floating point numbers and complex numbers.
  • 6. Data Type a. int (integer): Integer represents whole numbers. (positive or negative) e.g. -6, 0, 23466 b. float (floating point numbers): It represents numbers with decimal point. e.g. -43.2, 6.0 c. Complex numbers: It is made up of pair of real and imaginary number. e.g. 2+5j
  • 7. Data Type 2. String (str): It is a sequence of characters. (combination of letters, numbers and symbols). It is enclosed within single or double quotes. e.g. (‘ ’ or “ ”) >>> rem= “Hello Welcome to Python” >>> print (rem) Hello Welcome to Python
  • 8. Data Type 3. Boolean (bool): It represents one of the two possible values – True or False. >>> bool_1 = (6>10) >>> print (bool_1) False >>> bool_2 = (6<10) >>> print (bool_2) True
  • 9. Data Type 4. None: It is a special data type with single value. It is used to signify absence of value evaluating to false in a situation. >>> value_1 = None >>> print (value_1) None
  • 10. type() – if you wish to determine type of the variable. e.g. >>> type(10) <class ‘int’> >>> type(8.2) <class ‘float’> >>> type(“hello”) <class ‘str’> >>> type(True) <class ‘bool’> Data Type
  • 11. Value c) Value of variable Values are assigned to a variable using assignment operator (=).. e.g. >>>marks=87 >>>print(marks) 87 marks – Name of the variable Value of the variable 87
  • 12. Value The concept of assignment: There should be only one variable on the left-hand side of assignment operator. This variable is called Left value or L-value There can be any valid expression on the right-hand side of assignment operator. This variable is called Right value or R-value L-value = R-value Value_1 = 100 Variable Assignment operator Value
  • 13. Value Multiple assignments: We can declare multiple variables in a single statement. e.g. >>>x, y, z, p = 2, 40, 30.5, ‘Vinay’
  • 14. Variable Naming Convention 1. A variable name can contain letter, digits and underscore (_). No other characters are allowed. 2. A variable name must start with an alphabet or and underscore (_). 3. A variable name cannot contain spaces. 4. Keyword cannot be used as a variable name. 5. Variable names are case sensitive. Num and num are different. 6. Variable names should be short and meaningful. Invalid variable names – 3dgraph, roll#no, first name, d.o.b, while
  • 15. Input/Output Python provides three functions for getting user’s input. 1. input() function– It is used to get data in script mode. The input() function takes string as an argument. It always returns a value of string type.
  • 16. Input/Output 2. int() function– It is used to convert input string value to numeric value. 3. float() function – It converts fetched value in float type. 4. eval() – This function is used to evaluate the value of a string. It takes input as string and evaluates this string as number and return numeric result. NOTE : input() function always enter string value in python 3. So on need int(), float() function can be used for data conversion.
  • 17. Sample Program n1 = input("Enter first number") n2 = input("Enter second number") Sum=n1+n2 print("Sum is:", Sum)
  • 18. Sample Program n1 = eval(input("Enter first number")) n2 = eval(input("Enter second number")) Sum=n1+n2 print("Sum is:", Sum) n1 = int(input("Enter first number")) n2 = int(input("Enter second number")) Sum=n1+n2 print("Sum is:", Sum)
  • 19. Sample Program n1 = eval(input("Enter first number")) n2 = eval(input("Enter second number")) Sum=n1+n2 print("Sum is:", Sum) n1 = int(input("Enter first number")) n2 = int(input("Enter second number")) Sum=n1+n2 print("Sum is:", Sum)
  • 20. To calculate simple interest p = int(input("Enter Principal:")) r = float(input("Enter Rate:")) t = int(input("Enter Time:")) si=0.0 si=(p*r*t)/100 print("Simple Interest is:", si)
  • 21. m1 = int(input("Enter marks in English:")) m2 = int(input("Enter marks in Hindi:")) m3 = int(input("Enter marks in Maths:")) m4 = int(input("Enter marks in Science:")) m5 = int(input("Enter marks in Social Science:")) total=m1+m2+m3+m4+m5 per = total/5 print("Total is:", total) print("Percenatge is:", per) To calculate total and percentage
  • 22. Python Character Set A set of valid characters recognized by python. • Python uses the traditional ASCII character set. • The latest version recognizes the Unicode character set. The ASCII character set is a subset of the Unicode character set. Letters: a-z, A-Z Digits : 0-9 Special symbols : Special symbol available over keyboard White spaces: blank space, tab, carriage return, new line, form feed Other characters: Unicode
  • 23. Tokens Smallest individual unit in a program is known as token. 1. Keywords 2. Identifiers 3. Literals 4. Operators 5. Delimiters
  • 24. 1. Keywords Reserved word of the compiler/interpreter which can’t be used as identifier.
  • 25. 2. Identifiers A Python identifier is a name used to identify a variable, function, class, module or other object.
  • 26. 3. Literals Literals in Python can be defined as number, text, or other data that represent values to be stored in variables. Example of String Literals in Python name = ‘Johni’ , fname=“johny” Example of Integer Literals in Python(numeric literal) age = 22 Example of Float Literals in Python(numeric literal) height = 6.2 Example of Special Literals in Python name = None
  • 27. 3. Literals Escape sequence e.g. print(“I am a student of n APS t Yol Cantt”)
  • 28. 4. Operators Operators can be defined as symbols that are used to perform operations on operands. Types of Operators a. Arithmetic Operators. b. Relational Operators. c. Assignment Operators. d. Logical Operators. e. Membership Operators f. Identity Operators
  • 29. 4. Operators a. Arithmetic Operators. Arithmetic Operators are used to perform arithmetic operations like addition, multiplication, division etc.
  • 31. 4. Operators b. Relational Operators. Relational Operators are used to compare the values.
  • 32. print(5==3) False print(7>3) True print(15<7) False print(3!=2) True print(7>=8) False print(3<=4) True
  • 33. 4. Operators c. Assignment Operators. Used to assign values to the variables.
  • 35. 4. Operators d. Logical Operators. Logical Operators are used to perform logical operations on the given two variables or values. a=30 b=20 if(a==30 and b==20): print("hello") Output :- hello a=70 b=20 if(a==30 or b==20): print("hello")
  • 36. 4. Operators e. Membership Operators It used to validate whether a value is found within a sequence such as such as strings, lists, or tuples. E.g. a = 22 list = [11, 22,33,44] ans= a in list print(ans) Output: True E.g. a = 22 list = [11, 22,33,44] ans= a not in list print(ans) Output: False
  • 37. 4. Operators f. Identity Operators Identity operators in Python compare the memory locations of two objects.
  • 38.
  • 39. 5. Delimiters These are the symbols which can be used as separator of values or to enclose some values. e.g ( ) { } [ ] , ; :
  • 40. Token Category X Variable y Variable z Variable print Keyword ( ) Delimiter / Operator 68 Literal “x, y, z” Literal
  • 41. Comments Comments are statements in the script that are ignored by the Python interpreter. Comments (hash symbol = #) makes code more readable and understandable. # Program to assign value x=10 x=x+100 # increase value of x by 100 print(x)
  • 42. Expressions Expressions are combination of value(s). i.e. constant, variable and operators. Expression Value 5+2*4 13 8+12*2-4 28 Converting mathematical expression to equivalent Python expression Algebraic Expression Python Expression y = 3 ( 𝑥 2 ) y = 3 * x / 2 z= 3bc + 4 z = 3*b*c + 4
  • 43. User Defined Functions A function is a group of statements that exists within a program for the purpose of performing a specific task. Syntax: def function_name(comma_sep_list_parameters): statements
  • 44. User Defined Functions Example 1: def display(): print(“Welcome to pyhton”) >>>display() Example 2: def arearec(len, wd): area=len*wd return area >>>arearec(30, 10)