Python
Python
PYTHON INTRODUCTION
• List items are indexed( the first item has index [0], the
second item has index [1] etc.
LIST
• List support operation like concatenation using + operator.
• List items can be accessed by indexing- postive, negative indexing.
• List can be sliced.
• List can be mutable (ie, It is possible to change their content)
• In List we can add new item at the end by using append () method
• In list we can remove an item using del statement.
LIST – WE USE [ ] BRACKET
== EQUAL A==B
>>> A= 10
!= NOT EQUAL A!=B
>>>B=5
> GRAETER A>B
THAN >>>PRINT (A==B)
< LESS THAN A<B TRUE OR
FALSE
FALSE
>= GREATER A>=B
THAN OR
EQUAL TO >>> PRINT (A!=B)
<= LESS THAN A<=B
OR EQUAL
TRUE
TO
PYTHON LOGICAL OPERATORS
• It is used to combine conditional statements..The value is either True or False
>>> a=7
>>>b=12
>>> print (a<5 and b>10)
False
>>> print (a<5 or b>10)
LOGICAL True
NOT OPERATO AND >>>print(not (a<5 and b<10))
R
True
OR
IDENTITY OPERATORS
• 2 types
In( returns true if a sequence value is present in the object.)
• 2 types
• Break continue
If you want to terminate a loop and skip to The continue statement returns the
next code after the loop break statement will control to the beginning of the while loop
hel
DECISION MAKING STATEMENT-
• If statement
-it is used to test a particular condition
SYNTAX
If condition:
print statement
IF-ELSE STATEMENT
SYNTAX
If condition:
print statement 1
else:
print statement 2
ELIF STATEMENT
• - it helps to check multiple condtion.
SYNTAX
if condition 1:
block of statements 1
elif condition 2:
block of statements 2
elif condition 3:
block of statements 3
else :
block statement 4
PYTHON FUNCTIONS
• The function means a bock of code define with a name.
• If we need to perform the same task multiple times without writing the same
code again we use function.
• We can create our own functions (user-define functions.)
example: greet(), sum() , total()
• There are built-in functions also in python like
print() , input() , range ()
II.CALLING A FUNCTION
• Example
def greet(name):
print (“good morning” +name)
a =input(“Enter your name”)
greet(a)
CREATING A FUNCTION WITH PARAMETERS
AND RETURN VALUE
• Function can return a value.
• The return value is the output of the function.
• We want to the keyword return to return from a function.
• EXAMPLE
def sum(a,b):
Output
c= a+b Enter 1 number:
return c Enter 2 number:
Sum of number=
X= int (input (“Enter 1 number: “))
Y= int (input (“Enter 2 number: “))
print(“sum of above numbers=“,sum(x,y))