Posts

pw Python

  # # get ascii value from character # str="A" # print(ord(str)) # # get character from ascii value # ascii=65 # print(chr(ascii)) # # seprate # age=22 # name="ved" # percentage=89.98 # print(age,name,percentage,sep="-") output-> 22-ved-89.98 # # // operator - give near integer value # a=4 # b=3 # print(a//b) output-> 1 # #  identity operators compare the memory # #  locations of two objects to determine # #  if they are the exact same instance in memory. # a=5 # b=5 # print(a is b) # # membership operator - in , not in # # return true if a sequence with the specified value present in the object. # list=["ved","sneha","tarun","sam","dhruv"] # print("sam" in list) # print("prashant" not in list)

Tuple Python

  #  A BUILT IN DATA TYPE IMMUTABLE SEQUENCE OF VALUES # tup=(10,20,30,40,20) # print(type(tup)) # access element # print(tup[1]) # if tuple size is 1 , then we write with comma like- (1,) # tup=(1,) # print(tup) # slicing # print(tup[1:3]) # unpacking a tuple # tup=("ved","ram","sam") # n1,n2,n3=tup # print(n1,n2,n3) # METHODS-> # index() -  return index of first occurence # print(tup.index(20)) # count() -  count total occurence of element # print(tup.count(20)) # reverse tuple- # rev_tup=tuple(reversed(tup)) # print(rev_tup) # list=[] # for i in reversed(tup): #     list.append(i) # rev_tup=tuple(list) # print(rev_tup)

List Python

  # list allow to store multiple items of same/different data types in a single variable. #  property- index 0 based #  ordered #  mutable #  duplicates allowed # fruits=["apple","banana","mango","kibi"] # print(fruits) # print(type(fruits)) # print(len(fruits)) # if "banana" in fruits: #     print("true") # if "papaya" not in fruits: #     print("true") # accessing element of list # 1 indexing # 2 negative index # print(fruits[1]) # print(fruits[-2]) # sublist # 3 range of indexes # 4 range of negative index # print(fruits[0:3]) # print(fruits[-3:]) # adding element to a list # append() - add element at end of list # fruits.append("grapes") # print(fruits) # insert() - add element at given index # fruits.insert(1,"papaya") # print(fruits) # extend()- add another list in back # veg=["onion","tomato"] # fruits.extend(veg) # print(fruits) # removing element from list # ...

String Python

  # # str="""hello""" # print(str) # str="hello i am ved.\nhow you know me ?" # print(str) # # concatenation # s1="ved" # s2="varshney" # print(s1+s2) # # length of string # str="shradha"; # print(len(str)) # # access character from particular index , can not change   # str="noida" # ch=str[3] # print(ch) # # slicing string_name[i:j:step] j is not included # # if i , j not written , then default value assigned , step default value is 1 # upper bound does not matter # str="ved varshney" # print(str[1:7]) # print(str[1:]) # print(str[:3]) # str="pwskills" # print(str[0:8:2]) # print(str[::2]) # reverse print # print(str[::-1]) # # in pyhton , there is also negative indexing # # like string= d e l h i # #             -5-4-3-2-1 # str ="delhi" # print(str[-4:-1]) # strings function #str="i am ved varshney" # print(str.endswith("ed")) # # capitalize() - capitaliz...

Nested Loop Python

  # for i in range(4): #     print("*" *5) # n=int(input("enter row=")) # for i in range(n): #     for j in range(1,n+1): #         print(j,end=" ") #     print() # n=int(input("enter row=")) # for i in range(1,n+1):   #     for j in range(1,i+1): #         print(j,end=" ") #     print() # n=int(input("enter row=")) # for i in range(1,n+1): #     for j in range(1,i+1): #         print(chr(j+64),end=" ") #     print() # n=int(input("enter row=")) # for i in range(1,n+1): #     for j in range(1,n-i+1): #         print(" ",end=" ") #     for k in range(1,2*i): #         print(k,end=" ") #     print()

Loop Python

  # for i in range(1,10): , 10 is not include # range(start , stop , step) # if start value is not mention then it's value is 0 # for i in range(11): #     print(i) # 0 # 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # list=[10,20,30,40,50,60,70] # for i in list: #     print(i) # 10 # 20 # 30 # 40 # 50 # 60 # 70 # while loop # i=1 # while i<20: #     print(i) #     i+=1

Conditional Python

  # age=24 # if(age>=18): #     print("vote") #     print("drive") # # elif # num=0 # if(num>0): #     print("positive") # elif(num<0): #     print("negative") # else: #     print("zero") # num=78 # if num>=0: #     print("positive") # else: #     printf("negative") # num=int(input("enter number=")) # if(num%2==0): #     print("even") # else: #     print("odd") # cp=int(input("enter cost price=")) # sp=int(input("enter selling price=")) # if sp>cp: #     print("profit",(sp-cp)) # elif cp>sp: #     print("loss",(cp-sp)) # else: #     print("no profit , no loss") # num=int(input("enter a number=")) # if num>=1000 and num<=9999: #     print("4 digit number") # else: #     print("not 4 digit number") # # match case - switch case # a=int(input("enter 1st number=")) # b=int(input(...

Basic Python

  # print("i am ved.","i am 22 years old.") # print(2+3) # data types in python # age=22 # fullName="ved" # price=89.5 #print("my age is=",age) # print(type(age)) # print(type(fullName)) # print(type(price)) # we can not write true , only True in python # isFollow=True # print(isFollow) # None used for when there is no value assign # a=None # print(type(a)) # str1='ved' # str2="ved" # str3='''ved''' # print(str1) # print(str2) # print(str3) # python is case sensitive language # there are 35 keywords in python # a=2 # b=5 # sum=a+b # print(sum) # comment in python # 1st is use # # 2nd is use triple quots """   """ hey my name ved """ # / division operator gives result in decimal   # print(4/2) # 2.0 # ** is used for power a**b is a^b # logical operator - and , or , not # print(not True) # a=10 # b=20 # c=30 # print(a>b or a>c) # print(a<b and a>c) # ...

HashMap

  //in hashmap duplicate value can we insert but , duplicate key not , all are unique. import java . util . HashMap ;   public class Basic {     public static void main ( String [] args ) {     HashMap < Integer , String > map = new HashMap <>();     map . put ( 78 , "ved" );     map . put ( 99 , "sneha" );     map . put ( 89 , "tarun" );     map . put ( 90 , "rajan" );     System . out . println ( map );     // size of map     System . out . println ( map . size ());     //  get(key)- gives the value of key     System . out . println ( map . get ( 90 ));     // remove(key) - it delete key and pair both     map . remove ( 89 );     System . out . println ( map );     // check value is exist or not     System . out . println ( map . containsValue ( "sneha" ));     // check key is exist...

HashSet

  import java . util . HashSet ; // HashSet is an interface in java. // if we want to remove  an element which is not exist in set then we do not get any error. // in set there is no concept of index , so we use for each loop. // if any element is already present , then we can not add again , no error. public class Basic {     public static void main ( String [] args ) {         HashSet < Integer > set = new HashSet <>();         // Insert O(1)         set . add ( 89 );         set . add ( 10 );         set . add ( - 987 );         set . add ( 100 );         // size O(1)         System . out . println ( set . size ());         //in set elements are stroe randomly         System . out . println ( set );         // remove element O(...

linked list new version.

  class Sll { // user defined data structure     Node head ;     Node tail ;     int size ; void size (){     System . out . println ( "length of list is=" + size ); } void deleteAtIndex ( int ix ){ if ( ix < 0 || ix >= size ) throw new IndexOutOfBoundsException ( "invalid index" ); if ( ix == 0 ){   deleteAtStart ();   return ; } if ( ix == size - 1 ){     deleteAtEnd ();     return ; } Node x = head ; for ( int i = 0 ; i < ix - 1 ; i ++ ){     x = x . next ; } x . next = x . next . next ; size -- ;   } void deleteAtEnd (){ if ( head == null )     throw new IllegalStateException ( "list is already empty" );     if ( head == tail ){         head = tail = null ;         size -- ;         return ;     }     Node x = head ;     while ( x . next != tail ){   ...

linkedlist

class SLL {     private Node head ;     private Node tail ;     private int size ;     void deleteAtIndex ( int ix ){     if ( ix < 0 || ix >= size ){     throw new IndexOutOfBoundsException ( "bhai wrong index mat dal" );     }     if ( ix == 0 ){         deleteAtStart ();         return ;     }     if ( ix == size - 1 ){         deleteAtEnd ();         return ;     }     Node x = head ;     for ( int i = 0 ; i < ix - 1 ; i ++ ){         x = x . next ;     }       x . next = x . next . next ;       size -- ;     }     void deleteAtEnd (){         if ( tail == null ){             System . out . println ( "list is already empty" ...