Professional Documents
Culture Documents
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Identity operators
Membership operators
Bitwise operators
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical operators
Identity Operators
Contd..
x = ["apple", "banana"]
y = ["apple", "banana"]
z=x
print(x is z)
print(x is y)
# returns False because x is not the same object as y, even if they have the same content
print(x == y)
# to demonstrate the difference betweeen "is" and "==": this comparison returns True
because x is equal to y
Membership Operators
Contd..
x = ["apple", "banana"]
print("banana" in x)
# returns True because a sequence with the value "banana" is in the list
x = ["apple", "banana"]
print("pineapple" not in x)
def my_function(fname, lname):
print(fname + " " + lname)
my_function("Emil")
It throws an error.
Arbitrary Arguments, *args
def my_function(*students):
print("The student who logged in late is " + students[2])
my_function(“Vaishak", “Anandhu", “Seema")
Keyword arguments
You can also send arguments with the key = value syntax.
This way the order of the arguments does not matter.
Example:
def my_function(child3, child2, child1):
print("The youngest child is " + child3)
my_function("Sweden")
my_function("India")
my_function()
my_function("Brazil")
The pass Statement
def tri_recursion(k):
if(k > 0):
result = k + tri_recursion(k - 1)
else:
result = 0
return result
answer = tri_recursion(6)
print("\n\nRecursion Example Result",answer)
Finding addition of 2 numbers
def calculate_sum(data1, data2):
#All the statements in the block of code must have the
same level of indentation
result_sum=data1+data2
return result_sum
result=calculate_sum(10,20)
print(result)
Practise
Read 2 integers and return their sum if product is greater
than 1000 else return their product itself.
Take a list of numbers, return True if first and last number
of list is same.
Reverse a given number and return True if it same as
original number.
Given a string and an integer number n, remove characters
from string starting from zero upto n and return a new
string.
Contd..
Write a function to extract each digit from an integer in
reverse order.
Print Multiplication table from 1 to 10.
Given a list of numbers, iterate it and print only those
numbers which are divisible by 5.