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.
IMP PPT- Python programming fundamentals.pptx
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

PPTX
python fudmentalsYYour score increaseases
PPTX
Python PPT2
PDF
CS-XII Python Fundamentals.pdf
PPTX
PPTX
GRADE 11 Chapter 5 - Python Fundamentals.pptx
PPTX
009 Data Handling class 11 -converted.pptx
PPTX
009 Data Handling class 11 -converted.pptx
PDF
Data Handling_XI_Finall for grade 11 cbse board
python fudmentalsYYour score increaseases
Python PPT2
CS-XII Python Fundamentals.pdf
GRADE 11 Chapter 5 - Python Fundamentals.pptx
009 Data Handling class 11 -converted.pptx
009 Data Handling class 11 -converted.pptx
Data Handling_XI_Finall for grade 11 cbse board

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

PPTX
parts_of_python_programming_language.pptx
PPTX
Keep it Stupidly Simple Introduce Python
DOCX
unit 1.docx
PPTX
CH-3 FEATURES OF PYTHON, data types token
PPTX
DATA TYPE IN PYTHON
PPTX
Python variables and data types.pptx
PPTX
Python 3.pptx
PPTX
Python basics
PPT
Problem Solving Techniques
PDF
Advance Python Programming until operators.pdf
PPTX
Python programming
PPTX
Introduction to Python Programming language
PPTX
Python Programming - Variables, Objects and Classes
PPTX
PYTHON Introduction 1Deep learning 2.pptx
PPTX
What is python-presentation FOR CLASS 10.pptx
PPTX
What is python-presentation FOR CLASS 10.pptx
PPTX
Introduction to C Programming - R.D.Sivakumar
PPTX
009 Data Handling .pptx
PDF
C programming | Class 8 | III Term
parts_of_python_programming_language.pptx
Keep it Stupidly Simple Introduce Python
unit 1.docx
CH-3 FEATURES OF PYTHON, data types token
DATA TYPE IN PYTHON
Python variables and data types.pptx
Python 3.pptx
Python basics
Problem Solving Techniques
Advance Python Programming until operators.pdf
Python programming
Introduction to Python Programming language
Python Programming - Variables, Objects and Classes
PYTHON Introduction 1Deep learning 2.pptx
What is python-presentation FOR CLASS 10.pptx
What is python-presentation FOR CLASS 10.pptx
Introduction to C Programming - R.D.Sivakumar
009 Data Handling .pptx
C programming | Class 8 | III Term
Ad

Recently uploaded (20)

PPTX
1-4 Chaptedjkfhkshdkfjhalksjdhfkjshdljkfhrs.pptx
PDF
Invincible Season 2 Storyboard Revisions by Mark G
PPTX
PRESENTATION OF SEPSIS, SEPTIC SHOCK.pptx
PPTX
LIFE ORIENTATION SLIDES 2025 Grade 11.pptx
PPTX
加利福尼亚大学圣克鲁斯分校毕业证文凭办理|UCSC毕业证学历证书学位证
PPTX
Digital Marketing training in Chandigarh
PPTX
Top Bank Jobs in Jaipur Roles, Salaries & Smart Hiring Trends in 2025.pptx
DOCX
Digital Marketing In Chandigarh Excellence Technology
PPTX
First Homeroom Meeting in Dahlia SY2025-2026
PPTX
Understanding Present Worth for a better future
PDF
HR Jobs in Jaipur: 2025 Trends, Banking Careers & Smart Hiring Tools
PDF
Chapter 7-2.pdf. .
PPTX
Qjajwjwjwjwjwjwujsiwhshsuh22001002005.pptx
PDF
Invincible season 2 storyboard revisions seq2 by Mark G
PPTX
Q1 WEEK 2 -Understanding protective and risk factors, sense of.pptx
PPTX
Pre-Mendelian-and-Post-Mendelian-Concepts-of-Heredity (1).pptx
PDF
Villa Thesis-Final.pdf NNNNNNNNNNNNNNNNNNNNNNNNNNNNN
PPTX
_+✅+JANUARY+2025+MONTHLY+CA.pptx current affairs
PDF
Daisia Frank: Strategy-Driven Real Estate with Heart.pdf
PPT
NL5MorphologyAndFinteStateTransducersPart1.ppt
1-4 Chaptedjkfhkshdkfjhalksjdhfkjshdljkfhrs.pptx
Invincible Season 2 Storyboard Revisions by Mark G
PRESENTATION OF SEPSIS, SEPTIC SHOCK.pptx
LIFE ORIENTATION SLIDES 2025 Grade 11.pptx
加利福尼亚大学圣克鲁斯分校毕业证文凭办理|UCSC毕业证学历证书学位证
Digital Marketing training in Chandigarh
Top Bank Jobs in Jaipur Roles, Salaries & Smart Hiring Trends in 2025.pptx
Digital Marketing In Chandigarh Excellence Technology
First Homeroom Meeting in Dahlia SY2025-2026
Understanding Present Worth for a better future
HR Jobs in Jaipur: 2025 Trends, Banking Careers & Smart Hiring Tools
Chapter 7-2.pdf. .
Qjajwjwjwjwjwjwujsiwhshsuh22001002005.pptx
Invincible season 2 storyboard revisions seq2 by Mark G
Q1 WEEK 2 -Understanding protective and risk factors, sense of.pptx
Pre-Mendelian-and-Post-Mendelian-Concepts-of-Heredity (1).pptx
Villa Thesis-Final.pdf NNNNNNNNNNNNNNNNNNNNNNNNNNNNN
_+✅+JANUARY+2025+MONTHLY+CA.pptx current affairs
Daisia Frank: Strategy-Driven Real Estate with Heart.pdf
NL5MorphologyAndFinteStateTransducersPart1.ppt
Ad

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.
  • 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)