SlideShare a Scribd company logo
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

Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
HarishParthasarathy4
 
Python basics
Python basicsPython basics
Python basics
Manisha Gholve
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniquesvalarpink
 
Python programming
Python  programmingPython  programming
Python programming
Ashwin Kumar Ramasamy
 
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
Sivakumar R D .
 
009 Data Handling .pptx
009 Data Handling .pptx009 Data Handling .pptx
009 Data Handling .pptx
ssuser6c66f3
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III TermAndrew Raj
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
ssuser492e7f
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
rehanafarheenece
 
What is Paython.pptx
What is Paython.pptxWhat is Paython.pptx
What is Paython.pptx
Parag Soni
 
what-is-python-presentation.pptx
what-is-python-presentation.pptxwhat-is-python-presentation.pptx
what-is-python-presentation.pptx
Vijay Krishna
 
Data types in python
Data types in pythonData types in python
Data types in python
RaginiJain21
 
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
faithxdunce63732
 
python-presentation.pptx
python-presentation.pptxpython-presentation.pptx
python-presentation.pptx
Vijay 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 Fundamentals
Praveen 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.pptx
ChetanChauhan203001
 
Intro to python programming (basics) in easy language
Intro to python programming (basics) in easy languageIntro to python programming (basics) in easy language
Intro to python programming (basics) in easy language
MuhammadShahbaz36976
 
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
Prabha Karan
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
Raajendra M
 

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

Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
 
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 Paython.pptx
What is Paython.pptxWhat is Paython.pptx
What is Paython.pptx
 
what-is-python-presentation.pptx
what-is-python-presentation.pptxwhat-is-python-presentation.pptx
what-is-python-presentation.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
 
Intro to python programming (basics) in easy language
Intro to python programming (basics) in easy languageIntro to python programming (basics) in easy language
Intro to python programming (basics) in easy language
 
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
 

Recently uploaded

欧洲杯投注网站-欧洲杯投注网站推荐-欧洲杯投注网站| 立即访问【ac123.net】
欧洲杯投注网站-欧洲杯投注网站推荐-欧洲杯投注网站| 立即访问【ac123.net】欧洲杯投注网站-欧洲杯投注网站推荐-欧洲杯投注网站| 立即访问【ac123.net】
欧洲杯投注网站-欧洲杯投注网站推荐-欧洲杯投注网站| 立即访问【ac123.net】
foismail170
 
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
larisashrestha558
 
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR GeneralistHeidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
HeidiLivengood
 
Brand Identity For A Sportscaster Project and Portfolio I
Brand Identity For A Sportscaster Project and Portfolio IBrand Identity For A Sportscaster Project and Portfolio I
Brand Identity For A Sportscaster Project and Portfolio I
thomasaolson2000
 
The Impact of Artificial Intelligence on Modern Society.pdf
The Impact of Artificial Intelligence on Modern Society.pdfThe Impact of Artificial Intelligence on Modern Society.pdf
The Impact of Artificial Intelligence on Modern Society.pdf
ssuser3e63fc
 
New Explore Careers and College Majors 2024.pdf
New Explore Careers and College Majors 2024.pdfNew Explore Careers and College Majors 2024.pdf
New Explore Careers and College Majors 2024.pdf
Dr. Mary Askew
 
Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!
LukeRoyak
 
一比一原版(YU毕业证)约克大学毕业证如何办理
一比一原版(YU毕业证)约克大学毕业证如何办理一比一原版(YU毕业证)约克大学毕业证如何办理
一比一原版(YU毕业证)约克大学毕业证如何办理
yuhofha
 
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
foismail170
 
Digital Marketing Training In Bangalore
Digital  Marketing Training In BangaloreDigital  Marketing Training In Bangalore
Digital Marketing Training In Bangalore
nidm599
 
Interactive Dictionary AIDS-B.pptx aaaaaaaaaaaaaaaaaaaaaaaaaa
Interactive Dictionary AIDS-B.pptx aaaaaaaaaaaaaaaaaaaaaaaaaaInteractive Dictionary AIDS-B.pptx aaaaaaaaaaaaaaaaaaaaaaaaaa
Interactive Dictionary AIDS-B.pptx aaaaaaaaaaaaaaaaaaaaaaaaaa
23211a7274
 
DIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptxDIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptx
FarzanaRbcomcs
 
134. Reviewer Certificate in Computer Science
134. Reviewer Certificate in Computer Science134. Reviewer Certificate in Computer Science
134. Reviewer Certificate in Computer Science
Manu Mitra
 
Andrea Kate Portfolio Presentation.pdf
Andrea Kate  Portfolio  Presentation.pdfAndrea Kate  Portfolio  Presentation.pdf
Andrea Kate Portfolio Presentation.pdf
andreakaterasco
 
原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样
原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样
原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样
atwvhyhm
 
Personal Brand Exploration Comedy Jxnelle.
Personal Brand Exploration Comedy Jxnelle.Personal Brand Exploration Comedy Jxnelle.
Personal Brand Exploration Comedy Jxnelle.
alexthomas971
 
Midterm Contract Law and Adminstration.pptx
Midterm Contract Law and Adminstration.pptxMidterm Contract Law and Adminstration.pptx
Midterm Contract Law and Adminstration.pptx
Sheldon Byron
 
一比一原版(UVic毕业证)维多利亚大学毕业证如何办理
一比一原版(UVic毕业证)维多利亚大学毕业证如何办理一比一原版(UVic毕业证)维多利亚大学毕业证如何办理
一比一原版(UVic毕业证)维多利亚大学毕业证如何办理
pxyhy
 
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
foismail170
 
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Dirk Spencer Corporate Recruiter LION
 

Recently uploaded (20)

欧洲杯投注网站-欧洲杯投注网站推荐-欧洲杯投注网站| 立即访问【ac123.net】
欧洲杯投注网站-欧洲杯投注网站推荐-欧洲杯投注网站| 立即访问【ac123.net】欧洲杯投注网站-欧洲杯投注网站推荐-欧洲杯投注网站| 立即访问【ac123.net】
欧洲杯投注网站-欧洲杯投注网站推荐-欧洲杯投注网站| 立即访问【ac123.net】
 
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
 
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR GeneralistHeidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
 
Brand Identity For A Sportscaster Project and Portfolio I
Brand Identity For A Sportscaster Project and Portfolio IBrand Identity For A Sportscaster Project and Portfolio I
Brand Identity For A Sportscaster Project and Portfolio I
 
The Impact of Artificial Intelligence on Modern Society.pdf
The Impact of Artificial Intelligence on Modern Society.pdfThe Impact of Artificial Intelligence on Modern Society.pdf
The Impact of Artificial Intelligence on Modern Society.pdf
 
New Explore Careers and College Majors 2024.pdf
New Explore Careers and College Majors 2024.pdfNew Explore Careers and College Majors 2024.pdf
New Explore Careers and College Majors 2024.pdf
 
Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!
 
一比一原版(YU毕业证)约克大学毕业证如何办理
一比一原版(YU毕业证)约克大学毕业证如何办理一比一原版(YU毕业证)约克大学毕业证如何办理
一比一原版(YU毕业证)约克大学毕业证如何办理
 
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
 
Digital Marketing Training In Bangalore
Digital  Marketing Training In BangaloreDigital  Marketing Training In Bangalore
Digital Marketing Training In Bangalore
 
Interactive Dictionary AIDS-B.pptx aaaaaaaaaaaaaaaaaaaaaaaaaa
Interactive Dictionary AIDS-B.pptx aaaaaaaaaaaaaaaaaaaaaaaaaaInteractive Dictionary AIDS-B.pptx aaaaaaaaaaaaaaaaaaaaaaaaaa
Interactive Dictionary AIDS-B.pptx aaaaaaaaaaaaaaaaaaaaaaaaaa
 
DIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptxDIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptx
 
134. Reviewer Certificate in Computer Science
134. Reviewer Certificate in Computer Science134. Reviewer Certificate in Computer Science
134. Reviewer Certificate in Computer Science
 
Andrea Kate Portfolio Presentation.pdf
Andrea Kate  Portfolio  Presentation.pdfAndrea Kate  Portfolio  Presentation.pdf
Andrea Kate Portfolio Presentation.pdf
 
原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样
原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样
原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样
 
Personal Brand Exploration Comedy Jxnelle.
Personal Brand Exploration Comedy Jxnelle.Personal Brand Exploration Comedy Jxnelle.
Personal Brand Exploration Comedy Jxnelle.
 
Midterm Contract Law and Adminstration.pptx
Midterm Contract Law and Adminstration.pptxMidterm Contract Law and Adminstration.pptx
Midterm Contract Law and Adminstration.pptx
 
一比一原版(UVic毕业证)维多利亚大学毕业证如何办理
一比一原版(UVic毕业证)维多利亚大学毕业证如何办理一比一原版(UVic毕业证)维多利亚大学毕业证如何办理
一比一原版(UVic毕业证)维多利亚大学毕业证如何办理
 
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
 
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
 

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)