Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
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.
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.
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
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
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
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)
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")