Code By Shraddha
Tuesday, June 14, 2022
Wednesday, June 8, 2022
class and objects
class and object example:
class Person:
def __init__(self,name,age,city):
self.name = name
self.age = age
self.city = city
p1 = Person ("shraddha",19,"babra")
print (p1.name)
print(p1.age)
print(p1.city)
Tuesday, June 7, 2022
array
what is an array?
array is special variable ,which can hold more than one value at a time.
example:
car1 = " ford "
car2 = "bmw"
car3 ="volvo"
EXAMPLE:
modify the value of the first array item:
cars[0] = "toyota"
Monday, May 30, 2022
creating function and arguments
what is function :
a function is a block of code which only runs when is called.
you can pass data , known as parameters , into function .
a function can return data as result.
creating a fuction
in python a fuction is defined using the def keyword :
EXAMPLE:
Arguments
information can be passed into function as arguments
EXAMPLE:
Sunday, May 29, 2022
the while loops , break statement,continue statement
the while loops :
with the while loops we can execute a set of statement as long as condidtion is true
example:
a = 1
while a < 10:
print(a)
a = a+1
output:
the break statement:
i = 1
while i < 6:
print(i)
if i == 3:
break
i += 1
output:
the continue statement:
i = 0
while i < 6:
i += 1
if i == 3:
continue
print(i)
output:
lamda syntax and example
lambda:
lamda suction take take any type of arguments
syntax:
lambda arguments: expression
example:
x = lambda a:a+50
print(x(12))
x = lambda a ,b: a*b
print(x(20,2))
x = lambda a,b,c,d : a-b*c+d
print(x(20,2,2,15))
outout:
Friday, May 27, 2022
break statement
input:
fruits=["apple","pineapple","mango","python","C++"]
for b in fruits:
print(b)
if b == "python":
break
output:
phython built in data types
thislist=["apple","pineapple","mango"]
print(thislist)
thistuple=("apple","pineapple","mango")
print(thistuple)
thistuple=("apple","mango","apple","pineapple")
print(len(thistuple))
thisset={"apple","pineapple","mango"}
print(thisset)
output:
Wednesday, May 25, 2022
Python If...else Statement
1) simple if statement