SlideShare a Scribd company logo
MODULE : 1
Data types, Operator and expression, input and output statements.
Control structure – selective and Repetitive structure
What is Python
It is a high level programming language and interpreted program
language, we can execute the programs with less line of codes.
Syntax : print(“hello world”)  hello world
What is interpreter?
• Interpreters are the computer program that will convert the source code or an
high level language into intermediate code (machine level language). It is also
called translator in programming terminology. Interpreters executes each line of
statements slowly. This process is called Interpretation. For example Python is an
interpreted language, PHP, Ruby, and JavaScript.
Compiler vs interpreter
#include<iostream>
int main()
{
int a=10; output : 15
int b=5;
int c=a+b;
cout<<c;
return 0;
}
a=10 <<a=10
b=5 <<b=5
c=a+b <<c=15
print(c)
VARIABLES:
Python Variable is containers that store values. Python is not “statically typed”. We
do not need to declare variables before using them or declare their type. A variable is
created the moment we first assign a value to it. A Python variable is a name given to a
memory location.
RULES OF VARIABLES:
• A Python variable name must start with a letter or the underscore character.
• A Python variable name cannot start with a number.
• A Python variable name can only contain alpha-numeric characters and underscores (A-z,
0-9, and _ ).
• Variable in Python names are case-sensitive (name, Name, and NAME are three different
variables).
• The reserved words(keywords) in Python cannot be used to name the variable in Python.
Example 1 Example 2
a=20
b=30
c=40 output: 20
d=50 30
print(a) 40
print(b) 50
print(c)
print(d)
a=20
b=30
c=40 output: 20,30
d=50 40,50
print(a,b)
print(c,d)
EXAMPLE 3
age =20
salary =23.4 Output: 20, 23.4
name = “Abcd” Abcd
print(age,salary)
print(name)
EXAMPLE 4
a=b=c=10 EXAMPLE 5
print(a) Output: 10 a, b, c= 10,20,30 Output: 10
print(b) 10 print(a) 20
print(c) 10 print(b)
Data types:
• Numbers
• String
• Tuple
• List
• Set
• Dict
Number:
The numeric data type in Python represents the data that has a
numeric value. A numeric value can be an integer, a floating number, or even
a complex number. These values are defined as Python int, Python float,
and Python complex classes in Python.
• Integers – This value is represented by int class. It contains positive or
negative whole numbers (without fractions or decimals). In Python, there is
no limit to how long an integer value can be.
• Float – This value is represented by the float class. It is a real number with
a floating-point representation. It is specified by a decimal point.
Optionally, the character e or E followed by a positive or negative integer
may be appended to specify scientific notation.
• Complex Numbers – A complex number is represented by a complex class.
It is specified as (real part) + (imaginary part)j. For example – 2+3j
a = 5
print("Type of a: ", type(a))
b = 5.0
print("n Type of b: ", type(b))
c = 2 + 4j
print("n Type of c: ", type(c))
Output :
Type of a: <class 'int'>
Type of b: <class 'float'>
Type of c: <class 'complex'>
String:
Python are arrays of bytes representing Unicode characters. A string is a collection
of one or more characters put in a single quote, double-quote, or triple-quote. In Python
there is no character data type, a character is a string of length one. It is represented by str
class.
• Creating String
• Strings in Python can be created using single quotes, double quotes, or even triple
quotes.
• Example: This Python code showcases various string creation methods. It uses single
quotes, double quotes, and triple quotes to create strings with different content and
includes a multiline string. The code also demonstrates printing the strings and checking
their data types.
String1 = 'Welcome to the Geeks World'
print("String with the use of Single Quotes: ")
print(String1)
print('n’)
String1 = "I'm a Geek"
print("nString with the use of Double Quotes: ")
print(String1)
print(type(String1))
print('n’)
String1 = '''Geeks
For
Life'''
print("nCreating a multiline String: ")
print(String1)
Output:
String with the use of Single Quotes:
Welcome to the Geeks World
String with the use of Double Quotes:
I'm a Geek
<class 'str’>
Creating a multiline String:
Geeks
For
Life
LIST:
A group of comma separated values
enclosed in square bracket
Eg:- [10,20,30]
a= [5,5,5]
Print(type(a))
SET:
A group of comma separated value
enclosed with curly brackets.
Eg:- { 10,20,30}
a= {5,5,5}
print(type(a))
TUPLE:
A group of comma separated value
enclosed optionally in parenthesis.
Eg:- 10,20,30 or (10,20,30)
a= 5,5,5
print(type(a))
DICT:
A group of comma separated key-
value with enclosed curly brackets
Eg:- {“apple” : 10 , “ cat” : 20}
a={“ab” : 5 , “cd” : 5}
print(type(a))
Operators:
Operators are special symbols that perform operations on
variables and values. They are:
• Arithmetic operator
• Assignment operator
• Comparison (or) relational operator
• Logical operator
ARITHMETIC:-
OPERATOR OPEARATION EXAMPLE
1. + Addition 7+2 = 9
2. - Subtraction 7-2 = 5
3. * Multiplication 7*2 = 14
4. / Division 7/2 = 3.5
5. // Floor Division 7//2 = 3
6. % Modulo 7%2 = 1
7. ** Power 7**2 = 49
EXAMPLE:
a=7
b=2
print(a+b) Output: 9
print(a-b) 5
print(a*b) 14
print(a/b) 3.5
print(a//b) 3
print(a%b) 1
print(a**b) 49
Addition:-
a=int(input("enter values:"))
b=int(input("enter values:"))
print(a+b)
Subtraction:-
a=int(input("enter values:"))
b=int(input("enter values:"))
print(a-b)
Multiplication:-
a=int(input("enter values:"))
b=int(input("enter values:"))
print(a*b)
Division:-
a=int(input("enter values:"))
b=int(input("enter values:"))
print(a/b)
FloorDivision:-
a=int(input("enter values:"))
b=int(input("enter values:"))
print(a//b)
Power:-
a=int(input("enter values:"))
b=int(input("enter values:"))
print(a**b)
Modulo:-
a=int(input("enter values:"))
b=int(input("enter values:"))
print(a%b)
ASSIGNMENT:-
Operator Operation Example
= Assignment operator a=7
+= Addition Assign a+=1
( a=a+1)
-= Subtract Assign a-=1
*= Multiple Assign a*=1
/= Division Assign a/=1
%= Remainder Assign a%=1
**= Exponent Assign a**=2
Example:
Addition:-
a=5
b=2
a+=b
print(a)
(or)
a=int(input(“enter the values:”))
b=int(input(“enter the values:”))
a+=b
print(a)
Subtraction:-
a=5
b=2
a-=b
print(a)
(or)
a=int(input(“enter the values:”))
b=int(input(“enter the values:”))
a-=b
print(a)
Multiplication:-
a=5
b=2
a*=b
print(a)
(or)
a=int(input(“enter the values:”))
b=int(input(“enter the values:”))
a*=b
print(a)
Division:-
a=5
b=2
a/=b
print(a)
(or)
a=int(input(“enter the values:”))
b=int(input(“enter the values:”))
a/=b
print(a)
Remainder:-
a=5
b=2
a%=b
print(a)
(or)
a=int(input(“enter the values:”))
b=int(input(“enter the values:”))
a%=b
print(a)
Exponent:-
a=5
b=2
a**=b
print(a)
(or)
a=int(input(“enter the values:”))
b=int(input(“enter the values:”))
a**=b
print(a)
Comparison Operator:-
Operator Operation Example
== Is equal to 3==5
#false
!= Not equal to 3!=5
#true
> Greater than 3>5
#false
< lesser than 3<5
#true
>= greater or equal 3>=5
#false
<= lesser or equal 3<=5
#true
Example:-
Is equal to:-
a=5
b=2
print(a==b)
(or)
a=int(input(“enter the values:”))
b=int(input(“enter the values:”))
print(a==b)
Not equal to:-
a=5
b=2
print(a!=b)
(or)
a=int(input(“enter the values:”))
b=int(input(“enter the values:”))
print(a!=b)
Greater than:-
a=5
b=2
print(a>b)
(or)
a=int(input(“enter the values:”))
b=int(input(“enter the values:”))
print(a>b)
Lesser than:-
a=5
b=2
print(a<b)
(or)
a=int(input(“enter the values:”))
b=int(input(“enter the values:”))
print(a<b)
Greater than or equal to:-
a=5
b=2
print(a>=b)
(or)
a=int(input(“enter the values:”))
b=int(input(“enter the values:”))
print(a>=b)
Lesser than or equal to:-
a=5
b=2
print(a<=b)
(or)
a=int(input(“enter the values:”))
b=int(input(“enter the values:”))
print(a<=b)
Logical Operator:-
Logical operator are used to check whether an expression is
true or false. They are user in decision making.
Operator Operation Example
And a and b True: Only if both
. the operands are true
Or a or b True: if at least one of
. the operand is true
Not not a True: if the operand is
. false
a= int(input(“enter the value:”))
b=int(input(“enter the value:”))
(or)
a=4
b=3
print(a>b and a<b)
#false
print(a==b or a>=b)
#true
print(not a>b)
#false
EXPRESSION IN PYTHON:-
An expression is a combination of operators and operands that is
interpreted to produce some other values. In any programming
language, an expression is evaluated as per the precedence of its
operator. so that if there is more than one operator in an expression.
Their precedence decides which operation will be performed first. We
have many different type of expression in python. Lets discuss all types
along with some example:
1.CONSTANT EXP:-
There are the expressions that have constant values only.
Eg:- X = 15 + 1.3
print(X)
2.ARITHMETIC:-
An Arithmetic expression is a combination of numeric values,
operators, and sometimes parenthesis. The result of this type of
expression is also a numeric value. The operators used in this
expression are arithmetic operators like addition, subtraction, etc. here
are some arithmetic operators in python.
OPERATOR SYNTAX FUNCTIONING
+ X+Y ADDITION
- X-Y SUBTRACTION
* X*Y MULTIPLICATION
/ X/Y DIVISION
// X//Y QUOTIENT
% X%Y REMAINDER
** X**Y EXPONENTIATION
Example:-
x=40
y=12
add= x+y
sub=x-y
mul=x*y
div=x/y
print(add)
print(sub)
print(mul)
print(div)
3.ENTEGRAL EXP:-
These are the kind of expression that produce only integer result
after all computational and type conversion.
Eg:- a= 13
b= 12.0
c= a+ int(b)
print(c)
4.FLOATING EXP:-
These are the kind of exp which produce floating point number
as result after all computation and type conversions.
Eg:-
a=13
b=5
c= a/b
print(c)
5.RELATIONAL EXP:-
In these type of exp, arithmetic exp are written on both sides of
relational operator(>,<,>=,<=). Those arithmetic exp are evaluated first,
and then compared as per relational operator and produce a Boolean
output in the end. These exp are also called Boolean expression.
Eg:- a = 21
b = 13
c = 40
d = 37
x = (a+b) >= (d-c)
print(x)
6.LOGICAL EXP:-
These are kind of exp that result in true or false. It basically specifies one
or more conditions. For example (10 == 9) is a condition if 10 is equal to 9. As we
know it is not correct, so it will return false. Studying logical exp, we also come
across some logical operators which can be seen in logical exp most often, here
are some logical operations in python.
Operator Syntax Functioning
AND P and Q it return true if both P and Q
are true otherwise return false
OR P or Q it return true if at least one of
P and Q is true.
NOT not P if returns true, if condition P
is false.
Eg:-
P = (10 == 9)
Q = (7 > 5)
R = P and Q
S = P or Q
T = not P
print(R)
print(S)
print(T)
INPUT AND OUTPUT:-
How to use input method to get value from user?
Input is data entered by user in the program
In python input() function is available for input
SYNTAX:-
Variable=input(“No need to do type cast for string”)
Variable=int(input(“enter the number:”)) >>>enter the number:3
Variable=float(input(“enter value:”)) >>>enter value:2.4
Variable=bool(input(“enter:”)) >>>enter: True
Variable=complex(input(“enter value:”)) >>>enter value: 2+5j
OUTPUT:
Output can be displayed to the user using print statement.
SYNTAX:
print(expression/constant/variables)
print(“hello everyone”) >>>hello everyone
age=20
print(“My age is:”,age) >>>My age is:20
print(“hello”)
print(“nice to meet you”)
>>>hello
>>>nice to meet you
SEPARATE ARGUMENT:-
print(“hello” , ”everyone”, sep=‘**’)
>>>hello**everyone
END ARGUMENT:-
print(“hello”,”everyone”,sep=‘**’,end=‘ ‘)
print(“nice”, “to”, “meet”,”you”,sep=‘_’)
>>>hello**everyone nice_to_meet_you
a=5
b=8
print(a,b,sep=‘@’)
>>>5@8
FORMATTED STRING:-
• .format()
• f string
print(“{} {} everyone”.format(‘hi’,’how are you?’))
>>>hi how are you everyone
x=“Apple”
y=“Orange”
print(“{},{}”.format(x,y))
>>>Apple,Orange
print(f”{x},{y}”)
>>>Apple,Orange
Conditional statement:-
Selective:-
• if condition
• if else
• elif condition
• Nested if
if condition:-
In computer programming, the if statement is a conditional
statement. It is used to execute a block of code only when a
specific condition is met
number = 10
if number > 0:
print('Number is positive’)
print('This statement always executes')
if else:-
An if statement can have an optional else clause. The else statement
executes if the condition in the if statement evaluates to False
number = 10
if number > 0:
print('Positive number’)
else:
print('Negative number’)
print('This statement always executes’)
if elif else statement:-
The if...else statement is used to execute a block of code among two
alternatives.
However, if we need to make a choice between more than two alternatives,
we use the if...elif...else statement
.
Example for if elif else:-
number = 0
if number > 0:
print('Positive number’)
elif number <0:
print('Negative number’)
else:
print('Zero’)
print('This statement is always executed')
Nested if:-
It is possible to include an if statement inside another if statement
For example:-
number = 5
if number >= 0:
if number == 0:
print('Number is 0’)
else:
print('Number is positive’)
else:
print('Number is negative')
for loop:-
In Python programming, we use for loops to repeat some code a certain number of times. It
allows us to execute a statement or a group of statements multiple times by reducing the burden of
writing several lines of code.
Example:-
LOOP TO ITERATE THROUGH DICTIONARY:-
programmingLanguages = {'J':'Java','P':'Python'}
for key,value in programmingLanguages.items():
print(key,value)
LOOP USING ZIP() FOR PARALLEL ITERATION:-
a1 = ['Python','Java','CSharp']
b2 = [1,2,3]
for i,j in zip(a1,b2):
print(i,j)
NESTED LOOP IN PYTHON:-
list1 = [5,10,15,20]
list2 = ['Tomatoes','Potatoes','Carrots','Cucumbers']
for x in list1:
for y in list2:
print(x,y)
BREAK:-
vehicles = ['Car','Cycle','Bus','Tempo']
for v in vehicles:
if v == "Bus":
break
print(v)
CONTINUE:-
vehicles = ['Car','Cycle','Bus','Tempo']
for v in vehicles:
if v == "Bus":
continue
print(v)
COUNT THE NUMBER:-
numbers = [12,3,56,67,89,90]
count = 0
for n in numbers:
count += 1
print(count)
SUM OF ALL NUMBER:-
numbers = [12,3,56,67,89,90]
sum = 0
for n in numbers:
sum += n
print(sum)
TRIANGLE LOOP:-
for i in range(1,5):
for j in range(i):
print('*',end='')
print()
MAXIMUM NUMBER:-
numbers = [1,4,50,80,12]
max = 0
for n in numbers:
if(n>max):
max = n
print(max)
SORT THE NUMBER IN DECENDING ORDER:-
numbers = [1,4,50,80,12]
for i in range(0, len(numbers)):
for j in range(i+1, len(numbers)):
if(numbers[i] < numbers[j]):
temp = numbers[i]
numbers[i] = numbers[j];
numbers[j] = temp
print(numbers)
MULTIPLE OF 3 USING RANGE FUNCTION():-
for i in range(3,20,3):
print(i)
REVERSE ORDER:-
for i in range(10,0,-1):
print(i)
while loop:-
With the while loop we can execute a set of statements as long as a
condition is true.
Example:-
Print i as long as i is less than 6:
i = 1
while i < 6:
print(i)
i += 1
Break:-
Exit the loop when i is 3:
i = 1
while i < 6:
print(i)
if i == 3:
break
i += 1
Continue:-
Continue to the next iteration if i is 3:
i = 0
while i < 6:
i += 1
if i == 3:
continue
print(i)
else statement:-
Print a message once the condition is false:
i = 1
while i < 6:
print(i)
i += 1
else:
print("i is no longer less than 6")

More Related Content

PPT
PythonCourse_02_Expressions.ppt Python introduction turorial for beginner.
sakchaisengsui
 
PPTX
Python PPT2
Selvakanmani S
 
PPTX
Review old Pygame made using python programming.pptx
ithepacer
 
PPTX
unit1 python.pptx
TKSanthoshRao
 
PDF
python2oxhvoudhuSGFsughusgdogusuosFU.pdf
rohithzach
 
PPTX
Introduction to python programming ( part-1)
Ziyauddin Shaik
 
PPTX
Python
Sangita Panchal
 
PDF
PPE-Module-1.2 PPE-Module-1.2 PPE-Module-1.2.pdf
ArjayBalberan1
 
PythonCourse_02_Expressions.ppt Python introduction turorial for beginner.
sakchaisengsui
 
Python PPT2
Selvakanmani S
 
Review old Pygame made using python programming.pptx
ithepacer
 
unit1 python.pptx
TKSanthoshRao
 
python2oxhvoudhuSGFsughusgdogusuosFU.pdf
rohithzach
 
Introduction to python programming ( part-1)
Ziyauddin Shaik
 
PPE-Module-1.2 PPE-Module-1.2 PPE-Module-1.2.pdf
ArjayBalberan1
 

Similar to MODULE. .pptx (20)

PPTX
Learn about Python power point presentation
omsumukh85
 
PPTX
Revision-of-thehki-basics-of-python.pptx
PraveenaFppt
 
PPTX
Engineering CS 5th Sem Python Module-1.pptx
hardii0991
 
PPTX
Intro to CS Lec03 (1).pptx
FamiDan
 
PPTX
funadamentals of python programming language (right from scratch)
MdFurquan7
 
PPTX
unit1.pptx for python programming CSE department
rickyghoshiit
 
PPTX
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
yuvarajkumar334
 
PDF
03-Variables, Expressions and Statements (1).pdf
MirHazarKhan1
 
PPTX
Parts of python programming language
Megha V
 
PPTX
CLASS-11 & 12 ICT PPT PYTHON PROGRAMMING.pptx
seccoordpal
 
PPTX
03 Variables - Chang.pptx
Dileep804402
 
PPTX
Introduction to Python Values, Variables Data Types Chapter 2
Raza Ul Mustafa
 
PPTX
PPt Revision of the basics of python1.pptx
tcsonline1222
 
PPTX
parts_of_python_programming_language.pptx
Koteswari Kasireddy
 
PPTX
Pythonlearn-02-Expressions123AdvanceLevel.pptx
AninditaSarkarNaha
 
PDF
1_Python Basics.pdf
MaheshGour5
 
PDF
Introduction to Python
Mohammed Sikander
 
PPTX
PPT_1_9102501a-a7a1-493e-818f-cf699918bbf6.pptx
myatminsoe180
 
PDF
Python Objects
MuhammadBakri13
 
PPTX
Class 12 computer. 1 Python intro-1.pptx
rajaryash2
 
Learn about Python power point presentation
omsumukh85
 
Revision-of-thehki-basics-of-python.pptx
PraveenaFppt
 
Engineering CS 5th Sem Python Module-1.pptx
hardii0991
 
Intro to CS Lec03 (1).pptx
FamiDan
 
funadamentals of python programming language (right from scratch)
MdFurquan7
 
unit1.pptx for python programming CSE department
rickyghoshiit
 
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
yuvarajkumar334
 
03-Variables, Expressions and Statements (1).pdf
MirHazarKhan1
 
Parts of python programming language
Megha V
 
CLASS-11 & 12 ICT PPT PYTHON PROGRAMMING.pptx
seccoordpal
 
03 Variables - Chang.pptx
Dileep804402
 
Introduction to Python Values, Variables Data Types Chapter 2
Raza Ul Mustafa
 
PPt Revision of the basics of python1.pptx
tcsonline1222
 
parts_of_python_programming_language.pptx
Koteswari Kasireddy
 
Pythonlearn-02-Expressions123AdvanceLevel.pptx
AninditaSarkarNaha
 
1_Python Basics.pdf
MaheshGour5
 
Introduction to Python
Mohammed Sikander
 
PPT_1_9102501a-a7a1-493e-818f-cf699918bbf6.pptx
myatminsoe180
 
Python Objects
MuhammadBakri13
 
Class 12 computer. 1 Python intro-1.pptx
rajaryash2
 
Ad

Recently uploaded (20)

PPTX
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
PPTX
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
PDF
Zero carbon Building Design Guidelines V4
BassemOsman1
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PDF
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
PPTX
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
PDF
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
PDF
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
PDF
Software Testing Tools - names and explanation
shruti533256
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
PPT
Ppt for engineering students application on field effect
lakshmi.ec
 
PDF
Zero Carbon Building Performance standard
BassemOsman1
 
PDF
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PPTX
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PDF
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
Zero carbon Building Design Guidelines V4
BassemOsman1
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
Software Testing Tools - names and explanation
shruti533256
 
Inventory management chapter in automation and robotics.
atisht0104
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
Ppt for engineering students application on field effect
lakshmi.ec
 
Zero Carbon Building Performance standard
BassemOsman1
 
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
Ad

MODULE. .pptx

  • 1. MODULE : 1 Data types, Operator and expression, input and output statements. Control structure – selective and Repetitive structure
  • 2. What is Python It is a high level programming language and interpreted program language, we can execute the programs with less line of codes. Syntax : print(“hello world”)  hello world What is interpreter? • Interpreters are the computer program that will convert the source code or an high level language into intermediate code (machine level language). It is also called translator in programming terminology. Interpreters executes each line of statements slowly. This process is called Interpretation. For example Python is an interpreted language, PHP, Ruby, and JavaScript.
  • 3. Compiler vs interpreter #include<iostream> int main() { int a=10; output : 15 int b=5; int c=a+b; cout<<c; return 0; } a=10 <<a=10 b=5 <<b=5 c=a+b <<c=15 print(c)
  • 4. VARIABLES: Python Variable is containers that store values. Python is not “statically typed”. We do not need to declare variables before using them or declare their type. A variable is created the moment we first assign a value to it. A Python variable is a name given to a memory location. RULES OF VARIABLES: • A Python variable name must start with a letter or the underscore character. • A Python variable name cannot start with a number. • A Python variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ). • Variable in Python names are case-sensitive (name, Name, and NAME are three different variables). • The reserved words(keywords) in Python cannot be used to name the variable in Python.
  • 5. Example 1 Example 2 a=20 b=30 c=40 output: 20 d=50 30 print(a) 40 print(b) 50 print(c) print(d) a=20 b=30 c=40 output: 20,30 d=50 40,50 print(a,b) print(c,d)
  • 6. EXAMPLE 3 age =20 salary =23.4 Output: 20, 23.4 name = “Abcd” Abcd print(age,salary) print(name) EXAMPLE 4 a=b=c=10 EXAMPLE 5 print(a) Output: 10 a, b, c= 10,20,30 Output: 10 print(b) 10 print(a) 20 print(c) 10 print(b)
  • 7. Data types: • Numbers • String • Tuple • List • Set • Dict
  • 8. Number: The numeric data type in Python represents the data that has a numeric value. A numeric value can be an integer, a floating number, or even a complex number. These values are defined as Python int, Python float, and Python complex classes in Python. • Integers – This value is represented by int class. It contains positive or negative whole numbers (without fractions or decimals). In Python, there is no limit to how long an integer value can be. • Float – This value is represented by the float class. It is a real number with a floating-point representation. It is specified by a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientific notation. • Complex Numbers – A complex number is represented by a complex class. It is specified as (real part) + (imaginary part)j. For example – 2+3j
  • 9. a = 5 print("Type of a: ", type(a)) b = 5.0 print("n Type of b: ", type(b)) c = 2 + 4j print("n Type of c: ", type(c)) Output : Type of a: <class 'int'> Type of b: <class 'float'> Type of c: <class 'complex'>
  • 10. String: Python are arrays of bytes representing Unicode characters. A string is a collection of one or more characters put in a single quote, double-quote, or triple-quote. In Python there is no character data type, a character is a string of length one. It is represented by str class. • Creating String • Strings in Python can be created using single quotes, double quotes, or even triple quotes. • Example: This Python code showcases various string creation methods. It uses single quotes, double quotes, and triple quotes to create strings with different content and includes a multiline string. The code also demonstrates printing the strings and checking their data types.
  • 11. String1 = 'Welcome to the Geeks World' print("String with the use of Single Quotes: ") print(String1) print('n’) String1 = "I'm a Geek" print("nString with the use of Double Quotes: ") print(String1) print(type(String1)) print('n’) String1 = '''Geeks For Life''' print("nCreating a multiline String: ") print(String1)
  • 12. Output: String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek <class 'str’> Creating a multiline String: Geeks For Life
  • 13. LIST: A group of comma separated values enclosed in square bracket Eg:- [10,20,30] a= [5,5,5] Print(type(a)) SET: A group of comma separated value enclosed with curly brackets. Eg:- { 10,20,30} a= {5,5,5} print(type(a)) TUPLE: A group of comma separated value enclosed optionally in parenthesis. Eg:- 10,20,30 or (10,20,30) a= 5,5,5 print(type(a)) DICT: A group of comma separated key- value with enclosed curly brackets Eg:- {“apple” : 10 , “ cat” : 20} a={“ab” : 5 , “cd” : 5} print(type(a))
  • 14. Operators: Operators are special symbols that perform operations on variables and values. They are: • Arithmetic operator • Assignment operator • Comparison (or) relational operator • Logical operator
  • 15. ARITHMETIC:- OPERATOR OPEARATION EXAMPLE 1. + Addition 7+2 = 9 2. - Subtraction 7-2 = 5 3. * Multiplication 7*2 = 14 4. / Division 7/2 = 3.5 5. // Floor Division 7//2 = 3 6. % Modulo 7%2 = 1 7. ** Power 7**2 = 49
  • 16. EXAMPLE: a=7 b=2 print(a+b) Output: 9 print(a-b) 5 print(a*b) 14 print(a/b) 3.5 print(a//b) 3 print(a%b) 1 print(a**b) 49
  • 17. Addition:- a=int(input("enter values:")) b=int(input("enter values:")) print(a+b) Subtraction:- a=int(input("enter values:")) b=int(input("enter values:")) print(a-b) Multiplication:- a=int(input("enter values:")) b=int(input("enter values:")) print(a*b)
  • 18. Division:- a=int(input("enter values:")) b=int(input("enter values:")) print(a/b) FloorDivision:- a=int(input("enter values:")) b=int(input("enter values:")) print(a//b) Power:- a=int(input("enter values:")) b=int(input("enter values:")) print(a**b)
  • 20. ASSIGNMENT:- Operator Operation Example = Assignment operator a=7 += Addition Assign a+=1 ( a=a+1) -= Subtract Assign a-=1 *= Multiple Assign a*=1 /= Division Assign a/=1 %= Remainder Assign a%=1 **= Exponent Assign a**=2
  • 27. Comparison Operator:- Operator Operation Example == Is equal to 3==5 #false != Not equal to 3!=5 #true > Greater than 3>5 #false < lesser than 3<5 #true >= greater or equal 3>=5 #false <= lesser or equal 3<=5 #true
  • 28. Example:- Is equal to:- a=5 b=2 print(a==b) (or) a=int(input(“enter the values:”)) b=int(input(“enter the values:”)) print(a==b)
  • 29. Not equal to:- a=5 b=2 print(a!=b) (or) a=int(input(“enter the values:”)) b=int(input(“enter the values:”)) print(a!=b)
  • 30. Greater than:- a=5 b=2 print(a>b) (or) a=int(input(“enter the values:”)) b=int(input(“enter the values:”)) print(a>b)
  • 31. Lesser than:- a=5 b=2 print(a<b) (or) a=int(input(“enter the values:”)) b=int(input(“enter the values:”)) print(a<b)
  • 32. Greater than or equal to:- a=5 b=2 print(a>=b) (or) a=int(input(“enter the values:”)) b=int(input(“enter the values:”)) print(a>=b)
  • 33. Lesser than or equal to:- a=5 b=2 print(a<=b) (or) a=int(input(“enter the values:”)) b=int(input(“enter the values:”)) print(a<=b)
  • 34. Logical Operator:- Logical operator are used to check whether an expression is true or false. They are user in decision making. Operator Operation Example And a and b True: Only if both . the operands are true Or a or b True: if at least one of . the operand is true Not not a True: if the operand is . false
  • 35. a= int(input(“enter the value:”)) b=int(input(“enter the value:”)) (or) a=4 b=3 print(a>b and a<b) #false print(a==b or a>=b) #true print(not a>b) #false
  • 36. EXPRESSION IN PYTHON:- An expression is a combination of operators and operands that is interpreted to produce some other values. In any programming language, an expression is evaluated as per the precedence of its operator. so that if there is more than one operator in an expression. Their precedence decides which operation will be performed first. We have many different type of expression in python. Lets discuss all types along with some example: 1.CONSTANT EXP:- There are the expressions that have constant values only. Eg:- X = 15 + 1.3 print(X)
  • 37. 2.ARITHMETIC:- An Arithmetic expression is a combination of numeric values, operators, and sometimes parenthesis. The result of this type of expression is also a numeric value. The operators used in this expression are arithmetic operators like addition, subtraction, etc. here are some arithmetic operators in python. OPERATOR SYNTAX FUNCTIONING + X+Y ADDITION - X-Y SUBTRACTION * X*Y MULTIPLICATION / X/Y DIVISION // X//Y QUOTIENT % X%Y REMAINDER ** X**Y EXPONENTIATION
  • 39. 3.ENTEGRAL EXP:- These are the kind of expression that produce only integer result after all computational and type conversion. Eg:- a= 13 b= 12.0 c= a+ int(b) print(c) 4.FLOATING EXP:- These are the kind of exp which produce floating point number as result after all computation and type conversions. Eg:- a=13 b=5 c= a/b print(c)
  • 40. 5.RELATIONAL EXP:- In these type of exp, arithmetic exp are written on both sides of relational operator(>,<,>=,<=). Those arithmetic exp are evaluated first, and then compared as per relational operator and produce a Boolean output in the end. These exp are also called Boolean expression. Eg:- a = 21 b = 13 c = 40 d = 37 x = (a+b) >= (d-c) print(x)
  • 41. 6.LOGICAL EXP:- These are kind of exp that result in true or false. It basically specifies one or more conditions. For example (10 == 9) is a condition if 10 is equal to 9. As we know it is not correct, so it will return false. Studying logical exp, we also come across some logical operators which can be seen in logical exp most often, here are some logical operations in python. Operator Syntax Functioning AND P and Q it return true if both P and Q are true otherwise return false OR P or Q it return true if at least one of P and Q is true. NOT not P if returns true, if condition P is false.
  • 42. Eg:- P = (10 == 9) Q = (7 > 5) R = P and Q S = P or Q T = not P print(R) print(S) print(T)
  • 43. INPUT AND OUTPUT:- How to use input method to get value from user? Input is data entered by user in the program In python input() function is available for input SYNTAX:- Variable=input(“No need to do type cast for string”) Variable=int(input(“enter the number:”)) >>>enter the number:3 Variable=float(input(“enter value:”)) >>>enter value:2.4 Variable=bool(input(“enter:”)) >>>enter: True Variable=complex(input(“enter value:”)) >>>enter value: 2+5j
  • 44. OUTPUT: Output can be displayed to the user using print statement. SYNTAX: print(expression/constant/variables) print(“hello everyone”) >>>hello everyone age=20 print(“My age is:”,age) >>>My age is:20 print(“hello”) print(“nice to meet you”) >>>hello >>>nice to meet you
  • 45. SEPARATE ARGUMENT:- print(“hello” , ”everyone”, sep=‘**’) >>>hello**everyone END ARGUMENT:- print(“hello”,”everyone”,sep=‘**’,end=‘ ‘) print(“nice”, “to”, “meet”,”you”,sep=‘_’) >>>hello**everyone nice_to_meet_you a=5 b=8 print(a,b,sep=‘@’) >>>5@8
  • 46. FORMATTED STRING:- • .format() • f string print(“{} {} everyone”.format(‘hi’,’how are you?’)) >>>hi how are you everyone x=“Apple” y=“Orange” print(“{},{}”.format(x,y)) >>>Apple,Orange print(f”{x},{y}”) >>>Apple,Orange
  • 47. Conditional statement:- Selective:- • if condition • if else • elif condition • Nested if if condition:- In computer programming, the if statement is a conditional statement. It is used to execute a block of code only when a specific condition is met number = 10 if number > 0: print('Number is positive’) print('This statement always executes')
  • 48. if else:- An if statement can have an optional else clause. The else statement executes if the condition in the if statement evaluates to False number = 10 if number > 0: print('Positive number’) else: print('Negative number’) print('This statement always executes’) if elif else statement:- The if...else statement is used to execute a block of code among two alternatives. However, if we need to make a choice between more than two alternatives, we use the if...elif...else statement .
  • 49. Example for if elif else:- number = 0 if number > 0: print('Positive number’) elif number <0: print('Negative number’) else: print('Zero’) print('This statement is always executed')
  • 50. Nested if:- It is possible to include an if statement inside another if statement For example:- number = 5 if number >= 0: if number == 0: print('Number is 0’) else: print('Number is positive’) else: print('Number is negative')
  • 51. for loop:- In Python programming, we use for loops to repeat some code a certain number of times. It allows us to execute a statement or a group of statements multiple times by reducing the burden of writing several lines of code. Example:- LOOP TO ITERATE THROUGH DICTIONARY:- programmingLanguages = {'J':'Java','P':'Python'} for key,value in programmingLanguages.items(): print(key,value) LOOP USING ZIP() FOR PARALLEL ITERATION:- a1 = ['Python','Java','CSharp'] b2 = [1,2,3] for i,j in zip(a1,b2): print(i,j)
  • 52. NESTED LOOP IN PYTHON:- list1 = [5,10,15,20] list2 = ['Tomatoes','Potatoes','Carrots','Cucumbers'] for x in list1: for y in list2: print(x,y) BREAK:- vehicles = ['Car','Cycle','Bus','Tempo'] for v in vehicles: if v == "Bus": break print(v)
  • 53. CONTINUE:- vehicles = ['Car','Cycle','Bus','Tempo'] for v in vehicles: if v == "Bus": continue print(v) COUNT THE NUMBER:- numbers = [12,3,56,67,89,90] count = 0 for n in numbers: count += 1 print(count)
  • 54. SUM OF ALL NUMBER:- numbers = [12,3,56,67,89,90] sum = 0 for n in numbers: sum += n print(sum) TRIANGLE LOOP:- for i in range(1,5): for j in range(i): print('*',end='') print()
  • 55. MAXIMUM NUMBER:- numbers = [1,4,50,80,12] max = 0 for n in numbers: if(n>max): max = n print(max) SORT THE NUMBER IN DECENDING ORDER:- numbers = [1,4,50,80,12] for i in range(0, len(numbers)): for j in range(i+1, len(numbers)): if(numbers[i] < numbers[j]): temp = numbers[i] numbers[i] = numbers[j]; numbers[j] = temp print(numbers)
  • 56. MULTIPLE OF 3 USING RANGE FUNCTION():- for i in range(3,20,3): print(i) REVERSE ORDER:- for i in range(10,0,-1): print(i)
  • 57. while loop:- With the while loop we can execute a set of statements as long as a condition is true. Example:- Print i as long as i is less than 6: i = 1 while i < 6: print(i) i += 1 Break:- Exit the loop when i is 3: i = 1 while i < 6: print(i) if i == 3: break i += 1
  • 58. Continue:- Continue to the next iteration if i is 3: i = 0 while i < 6: i += 1 if i == 3: continue print(i) else statement:- Print a message once the condition is false: i = 1 while i < 6: print(i) i += 1 else: print("i is no longer less than 6")