Posts

Showing posts from February, 2022

requests module

#requests module allows user to send http requests using python import requests #this method is used to get data from the url #re=requests.get("https://nharishcoding.blogspot.com/2021/09/os-module") re1=requests.get( "https://financialmodelingprep.com/api/company/price/AAPL" ) print (re1.text) print (re1.status_code) #this function is used to post data to the server to the given url dic1={ "key1" : "value1" , "key2" : "value2" } url= "https://nharishcoding.blogspot.com/" re2=requests.post( url =url , data =dic1) print (re2.status_code)

different methods of calling a function

//different methods of calling a function //1. call by value //2. call by reference /*#include <stdio.h> int add(int x,int y)// function {     return x+y; } int main() {     int r, a=2,b=3;     r=add(a,b); //function called by value     printf("%d",r);     return 0; }*/ //called by reference-------------------------- #include <stdio.h> int func1 ( int  * address ) // function {     * address = 200 ;     } int main () {     int a = 2 ;     printf ( " %d \n " , a );     func1 (& a ); //function called by reference..in this address of value will be given as the argument     printf ( " %d " , a );     return 0 ; }

actual and formal parameters

#include <stdio.h> int add ( int x , int y ) // function // in this x & y are formal parameters {     return x + y ; } int main () {     int r , a = 2 , b = 3 ;     r = add ( a , b ); // calling the function //in this a & b are actual parameters     printf ( " %d " , r );     return 0 ; }

object introspection

# object introspection: it is an ability to determine the type of an object at runtime # python provides some built-in functions that are used for object introspection. They are # 1. type(): this function returns the type of an object. # 2. dir(): this function return list of methods and attributes associated with that object. # 3. str(): this function converts everything into a string. # 4. id(): this function returns a special id of an object. # there are many are there # type() import random print ( type (random)) print ( type ([ 1 , 2 , 3 ])) #------------------------------- # dir() a=[ 1 , 2 , 3 ] print ( dir (a)) #------------------------------- # str() a= 1 print ( type (a)) print ( type ( str (a))) #------------------------------ # id() b= 1 print ( "id:" , id (b))

property decorator

'''class person: def __init__(self,fname,lname): self.fname=fname self.lname=lname self.fullname=f"{self.fname} {self.lname}" #derived from above attributes not from object arguments p1=person("N","Harish") #object print(p1.fullname) p1.fname="software" #here i can change fname and lname print(p1.fname) print(p1.fullname) #fname changed but full name was not changed because it is not came from object arguments ''' #_______________________________________________________________________ # using property decorator we change directly the attribute see below code class person: def __init__ ( self , fname , lname): self .fname=fname self .lname=lname @property #due to this i can call fullname function as attribute that is without () after function def fullname ( self ): #getter if self .fname== None or self .lname== None : return "fullname was dele...

pointers

//pointer: variable which stores the address of another variable //pointer in c programming language can be declared using * (astric symbol) // NULL pointer: a pointer that is not assigned any value but NULL is known as the NULL pointer // * : it is the dereference operator (also called indirection operator) used to get the value at a given address // & : the address of operator '&' returns the address of a variable #include <stdio.h> int main ()   {     printf ( "lets learn about pointers \n " );     int a = 75 ;     int * ptr =& a ; // ptr points to a (pointer)     int * ptr2 = NULL ; // NULL pointer     int * ptr3 ; //garbage address(not used) if here we use NULL this will not become garbage     printf ( "the value of a is %d \n " ,* ptr );     printf ( "the address of a is %d \n " , ptr ); //|this both are same     printf ( "the address of a is %d \n " ,& a );   //| ...

pointer arithmetics

// pointer arithmetic // only these arithmetic operation we can do with pointers that is addition and subtraction // 1. + // 2. - // 3. ++ // 4. -- #include <stdio.h> int main () {     int a = 1 ;     int * ptr1 =& a ; //pointer     printf ( "value of pointer points to a: %d \n " ,* ptr1 );     printf ( "address of pointer points to a: %d \n " , ptr1 );     printf ( "addtion of pointer points to a: %d \n " , ptr1 + 1 ); //this will add the address number by the int data type size(4byte)     printf ( "subtraction of pointer points to a: %d \n\n " , ptr1 - 1 ); //this will subtract the address number by the int data type size(4byte)         printf ( "address of pointer points to a: %d \n " , ptr1 );     ptr1 ++; // it means (ptr11=ptr1+1)     printf ( "addition of pointer points to a: %d \n " , ptr1 );     return 0 ; }

pointer arithmetic with array

#include <stdio.h> int main () {     int aray [ 3 ]={ 2 , 5 , 10 };     // three ways to access pointer value     printf ( "value of 1st element: %d \n " , aray [ 0 ]);     printf ( "value of 1st element: %d \n " ,* aray );     printf ( "value of 1st element: %d \n\n " ,*(& aray [ 0 ]));     // two ways to access pointer address     printf ( "address of 1st element: %d \n " , aray );     printf ( "address of 1st element: %d \n\n " ,& aray [ 0 ]);     // two ways to access pointer address     printf ( "address of 2nd element: %d \n " , aray + 1 ); //this will not add 1 instead it will add 1 data type size and becomes 2nd elements address     printf ( "address of 2nd element: %d \n\n " ,& aray [ 1 ]);     printf ( "before addition: %d \n " , aray );     printf ( "after addition it becomes address of 3rd element: %d \n " , aray + 2 );  ...

2 Dimension Array

  #include <stdio.h> int main () {     int matrice [ 2 ][ 3 ]={{ 1 , 2 , 3 },   //1.row 2.column                        { 4 , 5 , 6 }}; //initialization of array of name "matrice" of 2 row and 3 columns with values     //accessing values of the array matrice[]     printf ( " %d " , matrice [ 0 ][ 0 ]);     return 0 ; } //-------------------------------------------------- //using for loop for giving values to the array /*#include <stdio.h> int main() {     int i,j;     int matrice[2][3];// 1.row 2.column     for(i=0;i<2;i++) //row number loop     {         for(j=0;j<3;j++)//row number loop         {             printf("enter %d%d value of matrice:",i,j);             scanf("%d",&matrice[i][j]);       ...

1 Dimension Array

  // there are many types of arrays like 1D, 2D, 3D etc #include <stdio.h> int main () {     int a [ 5 ]={ 1 , 2 , 3 , 4 , 5 }; //initialization of array of name "a" of size 5 with values     //accessing values of the array a[]     printf ( " %d " , a [ 0 ]);     return 0 ; } //---------------------------------------------------- //using for loop for giving values to the array /*#include <stdio.h> int main() {     int i;     int marks[5];     for(i=0;i<5;i++)     {         printf("enter value%d:",i);         scanf("%d",&marks[i]);     }     printf("\nthe values are\n");     for(i=0;i<5;i++)     {         printf("marks[%d]=%d\n",i,marks[i]);     }     return 0; } */

recursive function

  // using copy of the function inside the function is called recursion or recursive function #include <stdio.h> int factorial ( int n ); int main () {     int n , fact ;     printf ( "enter no of which u want factorial:" );     scanf ( " %d " ,& n );     fact = factorial ( n );     printf ( "factorial of %d is %d " , n , fact );     return 0 ; } int factorial ( int n ) {     if ( n == 0 || n == 1 )     {         return 1 ;     }     else     {         return n * factorial ( n - 1 );     } }