Posts

String in python.

  # 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 # str="noida" # ch=str[3] # print(ch) # # slicing string_name[i:j] j is not included # # if i , j not written , then default value assigned # str="ved varshney" # print(str[1:7]) # print(str[1:]) # print(str[:3]) # # 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() - capitalize 1st character , no change in og string # print(str.capitalize()) # # replace()- replace all old character with new character # print(str.replace("a","x")) # print(str.replace("ved","sam")) # # find()- ...

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(...

python.

No, you cannot use the dollar sign ( $ ) in a Python variable name.   we can use 3 way to print string - ',",'''. single ,double, triple quotes.

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" ...

interface

 interface ICalculator{ // public and abstract void add(int a, int b); void sub(int a, int b); void mul(int a, int b); void div(int a, int b); } class Cal implements ICalculator{   public void add(int a , int b){       System.out.println("the sum is="+(a+b));   }   public void sub(int a , int b){       System.out.println("the subtraction is="+(a-b));   }   public void mul(int a , int b){       System.out.println("the multiplication is="+(a*b));   }   public void div(int a , int b){       System.out.println("the division is="+(a/b));   } } public class Main { public static void main(String[] args) { ICalculator c = new Cal(); c.add(10,20); c.sub(4,2); c.mul(2,8);     c.div(9,3); } } ------------------------------------------------------------------------------------------------------------------ interface ICalculator1{ // public and abstract void add(int a,...