Posts

while loop in python

 while loop in python # while loop : """ while(i<45): print(i) i = i + 2 while(i<200): i = i + 1 print(i) """ i= 0 while ( True ): if i+ 1 < 5 : i=i+ 1 continue print (i+ 1 , end = " " ) if (i== 44 ): i = i + 1 break

for loop

for loop in python   # for loop: # for i in range (11): # print(i) list1 = [ [ "Jetha" , 10 ],[ "Nihil" , 200 ],[ "Goli" , 60 ],[ "Daya" , 9 ],[ "Hathi" , 250 ]] for i1,dabeli in list1: if dabeli >= 1 : print (i1, "Eats" ,dabeli, "Dabeli" )

If ,else and elif

If ,else and elif    # if, else and elif: var1 = 6 var2 = 56 var3 = int ( input ()) if var3>var2 : print ( "Greater" ) elif var3<var2: print ( "Lesser" ) else : print ( "Equal" ) #list = [4,7,8,9] #print(7 in list) #Quiz """print("What is your age ?") age = int(input()) if age>100: print("Enter valid age.") elif age>18: print("You can drive.") elif age==18: print("We cant decide you have to come here.") else: print("You can't drive.")"""

Sets in python

Sets in Python   s = set () print ( type (s)) s.add( 1 ) s.add( 2 ) s1 = { 4 , 8 } print (s.isdisjoint(s1)) print (s.union(s1)) print (s.intersection(s1))

Dictionary and its functions

Dictionary and its functions # Dictionary & It's Functions dt = { "event" : "annual function" , "author" : "ngoyp" , "subject" : "pollution" , "standad" : "8" , "year" : "tewnty one" } #print(dt.get("author")) """dt.update("rank" "first") print(dt) """ #Exercise 1 : d2 = { "see" : "watch" , "laugh" : "mock" , "tough" : "hard" , "know" : "inquire" , "happy" : "joy" } ipt = input () print (ipt + " meaning is :" +d2[ipt])

Python list and listing functions

Image
Python list and listing functions  #listing functions #list = ["parth","gayatri","vaishu","naru",7,8.90] #print(list) #pa = [1,1,4,2,9,0] #pa.sort() #pa.reverse() #pa.remove(2) #pa.append(90) #pa.insert(3,4) """print(pa[1]) pa.pop() print(pa) pa[1]=98 print(pa) """ #mutable = can change #immmutable = can't change """tp = (1,2,3) print(tp) a = 4 b = 5 a,b=b,a print(a,b) """ #pa.pop(2) #print(pa) pa = [ 'almond' , 'cashew' , 'nut' , 'kismis' , 'kismis' , 'almond' ] pa.reverse() print (pa) pa.append( 'pista' ) print (pa) pa.pop( 2 ) print (pa)

String slicing and related functions

Image
 String slicing and related functions str = "my cat is piebald" print (str) """ print(len(str)) print(str[12]) print(str[0:6]) print(str[0:17:2]) print(str[-12])""" print (str[::- 1 ]) #print(str[::]) """print(str.isalnum()) print(str.isalpha()) print(str.endswith("is")) print(str.endswith("ld")) print(str.count("i")) print(str.capitalize()) print(str.upper()) print(str.lower()) print(str.replace("cat","dog")) print(str.find("is")) """