Basic fundamentals of python part 4

By // No comments:
There are many built-in functions available in Python Language. We can use this functions in any program and make your program easy.Here we will learn some important mathematical functions and use it in python programs.
Built-in Mathematical functions:-
  • pow(x,y)               #value of x raised to y
  • abs(x)                  #absolute value of x
  • min(x1,x2)           #smallest value
  • max(x1,x2)          #largest value
  • divmod(x,y)         #return a pair(x//y,x%y)
  • bin(x)                  # binary value
  • oct(x)                  # octal value
  • hex(x)                 #hexadecimal value
  • round(x[,n])         # x rounded to n digit after decimal point
  • sum(number,start) #sum function contains two arguments,start is optional argument.
  • any(x)                     # it returns True or false value,x can be list,string , dictionary etc.
  • all(x)                       # it returns True or false value .x can be list , string , dictionary etc.
  • ascii(object)           # it return a string,it takes arguments like integer string,list,etc
  • bool(value)             # bool() function takes a single parameter,it return True OR False
  • complex(a,b)           #It returns a complex number.it takes integer value only.
Python Program to implement above functions:-

pow(2,3)           # 8 will be(x^y) returned
print("power value is=",pow(2,3))
pow(-2,2)          # 4 will be(x^y) returned
print("power value is=",pow(-2,2))
pow(-1,-2)         # 1.0 will be(x^y) returned
print("power value is=",pow(-1,-2))
pow(2.5,2)         # 6.25 will be(x^y) returned
print("power value is=",pow(2.5,2))
pow(5,3,4)         # 1 will be [(x**y)%z] returned
print("power value is=",pow(5,3,4))

abs(-20)           #integer absolute value is returned
print("absolute value is=",abs(-20))
abs(-10.55)        #float absolute value is returned
print("absolute value is=",abs(-10.55))
abs(2-3j)          #magnitude of the number is returned
print("absolute value is=",abs(2-3j))

min(5,-8)          # minimum value -8 is returned
print("minimum value is=",min(5,-8))
list1=[2,3,-2,5,9] # minimum value -2 is returned
min(list1)
print("minimum value is=",min(list1))
list2=['ram','mohan','abc'] #least ordered alphabet is returned
min(list2)
print("minimum value is=",min(list2))
dic={1:3,2:4,3:-1}  #minimum key value will print of dictionary
min(dic)
print("minimum value is=",min(dic))

max(-8,7)          # maximum value 7 is returned
print("maximum value is=",max(-8,7))
list1=[2,3,-2,5,9] # maximum value 9 is returned
max(list1)
print("maximum value is=",max(list1))
list2=['ram','mohan','abc'] #maximum ordered alphabet is returned
max(list2)
print("maximum value is=",max(list2))
dic={1:3,2:4,3:-1}  #maximum key value will print of dictionary
max(dic)
print("maximum value is=",max(dic))

divmod(5,2)        #5//2 and 5%2 will be returned
print("divmod value is=",divmod(5,2))
divmod(5.7,2.5)        #5//2 and 5%2 will be returned
print("divmod value is=",divmod(5.7,2.5))

bin(5)             # bin()fuction can contains three arguments(integer,octal,hexadecimal)
bin(0o5)
bin(0x5)
print("binary value is=",bin(5),bin(0o5),bin(0x5))

oct(5)            # oct()fuction can contains three arguments(integer,binary,hexadecimal) 
oct(0b101)
oct(0x5)
print("octal value is=",oct(5),oct(0b101),oct(0x5))

hex(5)            # hex()fuction can contains three arguments(integer,octal,binary) 
hex(0b101) 
hex(0o5)
print("hexadecimal value is=",hex(5),hex(0b101),hex(0o5))

round(10)         # it rounds 0 decimal palace,default value of round is 0(zero)
print("round value is=",round(10))
round(10.5)
print("round value is=",round(10.5))
round(10.5678,2)
print("round value is=",round(10.5678,2))
round(10.78432,3)
print("round value is=",round(10.78432,3))

#sum(number,start)   #sum function contains two arguments,start is optional argument.
number=[1,2,3,4,-1]
sum(number)
print("sum value is=",sum(number))
sum(number,10)      #add the value from left to right
print("sum value is=",sum(number,10))

#any(x)              # it returns True or false value .x can be list,string,dictionary etc.
x=[1,2,3,4]
any(x)
print("any value is=",any(x))
x=[0,False]
any(x)
print("any value is=",any(x))
x=[0,False,3,4]
any(x)
print("any value is=",any(x))
x=''
any(x)
print("any value is=",any(x))

#all(x)              # it returns True or false value .x can be list,string,dictionary etc.
x=[1,2,3,4]
all(x)
print("all value is=",all(x))
x=[0,False]
all(x)
print("all value is=",all(x))
x=[0,False,3,4]
all(x)
print("all value is=",all(x))
x=''
all(x)
print("all value is=",all(x))

#ascii(object)           # it return a string,it takes arguments like integer string,list,etc.
str='i am a student'
ascii(str)
print("ascii value is=",ascii(str))
str1="i am 'a' student"
ascii(str)
print("ascii value is=",ascii(str))
ascii(12)
print("ascii value is=",ascii(str))

#bool(value)        # bool() function takes a single parameter,it return True OR False
str=[1,2,3]
bool(str)
print("bool value is=",bool(str))
str=[]
bool(str)
print("bool value is=",bool(str))
str='0'
bool(str)
print("bool value is=",bool(str))
str=''
bool(str)
print("bool value is=",bool(str))

#complex number

real=2
imag=3
print('complex number =',complex(real,imag))
print('complex number =',complex(1.5,3.5))
print('complex number =',complex('2'))
#print('complex number =',complex('2','3'))  #can't take second argument if first is string   
c=4+5j
print('complex number Real part =',c.real)
print('complex number Real part =',c.imag)
print('complex number conjugate =',c.conjugate())
#mathematical operations in complex number
c1=4+6j
c2=1+2j
print('addition of two complex number=',c1+c2)
print('subtractions of two complex number=',c1-c2)
print('multiplication of two complex number=',c1*c2)
print('division of two complex number=',c1/c2) 

Python Program Output:-

power value is= 8
power value is= 4
power value is= 1.0
power value is= 6.25
power value is= 1
absolute value is= 20
absolute value is= 10.55
absolute value is= 3.605551275463989
minimum value is= -8
minimum value is= -2
minimum value is= abc
minimum value is= 1
maximum value is= 7
maximum value is= 9
maximum value is= ram
maximum value is= 3
divmod value is= (2, 1)
divmod value is= (2.0, 0.7000000000000002)
binary value is= 0b101 0b101 0b101
octal value is= 0o5 0o5 0o5
hexadecimal value is= 0x5 0x5 0x5
round value is= 10
round value is= 10
round value is= 10.57
round value is= 10.784
sum value is= 9
sum value is= 19
any value is= True
any value is= False
any value is= True
any value is= False
all value is= True
all value is= False
all value is= False
all value is= True
ascii value is= 'i am a student'
ascii value is= 'i am a student'
ascii value is= 'i am a student'
bool value is= True
bool value is= False
bool value is= True
bool value is= False
complex number = (2+3j)
complex number = (1.5+3.5j)
complex number = (2+0j)
complex number Real part = 4.0
complex number Real part = 5.0
complex number conjugate = (4-5j)
addition of two complex number= (5+8j)
subtractions of two complex number= (3+4j)
multiplication of two complex number= (-8+14j)
division of two complex number= (3.2-0.4j)

Note:-Complex number doesn't support comparison operators(c1>c2,c1<c2 etc.)
Watch Lecture 7 Complete Video:-


Library Functions:-
For performing sophisticated mathematical operations,we can use the functions present in modules:-
  • Math:- It is used for useful mathematics functions.
  • cmath:- It is used for performing operations on complex numbers.
  • decimal:- It is used for performing arithmetic operations.
  • random :- It is used for performing number random number generations. 
There are some mathematical functions in math module as follows:- 
  • pi,e                          # It is constants
  • sqrt(x)                     #calculate square root of x
  • fabs(x)                    # calculate absolute vale of float x    
  • factorial(x)              # calculate factorial of x
  • log(x)                     # calculate log of x       
  • log10(x)                 # calculate base 10 log of x
  • exp(x)                   # calculate e raised to x
  • turn(x)                  # truncates to integer       
  • ceil(x)                   # calculate smallest integer >= x
  • floor(x)                 # calculate largest integer <= x
  • modf(x)                # calculate fractional and integer part of x
  • round(x)               # Round to a specific number of decimal places.
Note:- round() function is used to round to a specific number of decimal places,whereas trunc() , ceil()  and floor() functions always round to zero decimal places.

There are some Trigonometric functions in math module as follows:-
  • degrees(x)            # calculate radians to degree 
  • radians(x)           # calculate degree to radians 
  • sin(x)                 # calculate sine of x radians 
  • cos(x)                # calculate cosine of x radians
  • tan(x)                # calculate tan of x radians
  • sinh(x)               # calculate hyperbolic sine of x 
  • cosh(x)              # calculate hyperbolic cosine of x 
  • tanh(x)              # calculate hyperbolic tan of x 
  • asin(x)               # calculate sine inverse of x, in radians
  • acos(x)               # calculate cos inverse of x, in radians
  • atan(x)               # calculate tan inverse of x, in radians
  • hypot(x,y)           # calculate  sqrt(x*x+y*y)

import math

print("Value of pi =",math.pi)
print("Value of pi =",math.pi)

print("Value of square root =",math.sqrt(25))

print("Value of fabs =",math.fabs(12.3450))

print("Value of factorial =",math.factorial(4))

print("Value of log(x) =",math.log(5))
print("Value of log10(x) =",math.log10(5))

print("Value of exp(x) =",math.exp(2))

a=2.65
b=-3.15

print("Value of trunc =",math.trunc(a))
print("Value of trunc =",math.trunc(b))

print("Value of ceil =",math.ceil(a))
print("Value of ceil =",math.ceil(b))

print("Value of floor =",math.floor(a))
print("Value of trunc =",math.floor(b))

print("Value of round =",round(a))
print("Value of round =",round(b))

print("Value of pi radian in degrees =",math.degrees(math.pi))
print("Value of degrees in radians =",math.radians(180))

print("Value of sin =",math.sin(10))
print("Value of cos =",math.cos(10))
print("Value of tan =",math.tan(10))
print("Value of sinh =",math.sinh(5))
print("Value of cosh =",math.cosh(5))
print("Value of tanh =",math.tanh(10))
print("Value of asin =",math.asin(1))
print("Value of acos =",math.acos(1))
print("Value of atan =",math.atan(1))
print("Value of hypot =",math.hypot(0,5))
Above program output:-
Value of pi = 3.141592653589793
Value of pi = 3.141592653589793
Value of square root = 5.0
Value of fabs = 12.345
Value of factorial = 24
Value of log(x) = 1.6094379124341003
Value of log10(x) = 0.6989700043360189
Value of exp(x) = 7.38905609893065
Value of trunc = 2
Value of trunc = -3
Value of ceil = 3
Value of ceil = -3
Value of floor = 2
Value of trunc = -4
Value of round = 3
Value of round = -3
Value of pi radian in degrees = 180.0
Value of degrees in radians = 3.141592653589793
Value of sin = -0.5440211108893698
Value of cos = -0.8390715290764524
Value of tan = 0.6483608274590866
Value of sinh = 74.20321057778875
Value of cosh = 74.20994852478785
Value of tanh = 0.9999999958776927
Value of asin = 1.5707963267948966
Value of acos = 0.0
Value of atan = 0.7853981633974483
Value of hypot = 5.0

decimal module:- It is used for mathematical operations in python

import decimal
print('decimal value is=',0.2)
a=1.1
b=2.4
c=a+b
print('decimal value is=',c)
Above python code Output:-
decimal value is= 0.2
decimal value is= 3.5

cmath module:-Python cmath module provides access to mathematical functions for complex numbers.

import cmath
c=2+3j
modulus=abs(c)
phase=cmath.phase(c)
polar=cmath.polar(c)
print('complex number modulus is=',modulus)
print('complex number phase is=',phase) #angle between vector line and real axis
print('complex number polar coordinates is=',polar) #the straight line joining the two points at which tangents from a fixed point touch a conic section
print('rectangle co-ordinate value is=',cmath.rect(modulus,phase))
print('value of pi is =',cmath.pi)
print('value of e is =',cmath.e)
print('value of exonant is =',cmath.exp(c))
print('value of log2c is =',cmath.log(c,2))
print('value of log10c is =',cmath.log10(c))
print('value of sqrt is =',cmath.sqrt(c))
print('value of sine is =',cmath.sin(c))
print('value of inverse sine is =',cmath.asin(c))
print('value of sine hyperbolic is =',cmath.sinh(c))
print('value of inverse sine hyperbolic is =',cmath.asinh(c))
Above python code Output:-
complex number modulus is= 3.605551275463989
complex number phase is= 0.982793723247329
complex number polar coordinates is= (3.605551275463989, 0.982793723247329)
rectangle co-ordinate value is= (2+2.9999999999999996j)
value of pi is = 3.141592653589793
value of e is = 2.718281828459045
value of exonant is = (-7.315110094901103+1.0427436562359045j)
value of log2c is = (1.850219859070546+1.417871630745722j)
value of log10c is = (0.5569716761534184+0.42682189085546657j)
value of sqrt is = (1.6741492280355401+0.8959774761298381j)
value of sine is = (9.15449914691143-4.168906959966565j)
value of inverse sine is = (0.5706527843210994+1.9833870299165355j)
value of sine hyperbolic is = (-3.5905645899857794+0.5309210862485197j)
value of inverse sine hyperbolic is = (1.9686379257930964+0.9646585044076028j)

Random number generation functions in random module:-
  • random()                    #generate random number between 0.0 & 1.0.
  • randint(start,stop)     #generate random number in given range.
  • seed (x)                     #map seed value used in random number generation logic.
  • randrange(start,stop,step)                 #it returns a randomly selected element from the given range created by the start,stop and step and step argument
  • choice()               #It returns element randomly from the given list.if list is empty then it so index error.
  • shuffle()              #this function is used to randomly records the elements in the list.
  • print()                        # it can be used for sending  output to screen.

import random
print("Value of round =",random.random())
random.seed(20)

print(random.random())
random.seed(10)
print(random.random())

print("Value of round_integer =",random.randint(1,100))
print("Value of round_integer =",random.randint(30,95))

print("Value of round_range =",random.randrange(1,10,2))
print("Value of round_range =",random.randrange(1,10,3))

print("Value of round_choice =",random.choice('Ramashanker'))
print("Value of round_choice =",random.choice([10,14,50,70,23,26,80,93]))
number=[10,50,40,20,28,47]
print("Value of round_shuffle =",random.shuffle(number))
print("Value of round_shuffle_recorded =",number)
Above python program output:-
Value of round = 0.10603902641997465
0.9056396761745207
0.5714025946899135
Value of round_integer = 55
Value of round_integer = 91
Value of round_range = 9
Value of round_range = 1
Value of round_choice = a
Value of round_choice = 93
Value of round_shuffle = None
Value of round_shuffle_recorded = [28, 47, 10, 50, 40, 20]
Note:- we have to import that respective modules first in your program,to use respective functions present in that modules.

Watch complete Video:-
3

Basic fundamentals of python part 3

By // No comments:
Some Operations and type Conversions:-
This concepts is more helpful for beginners and professionals.You can learn python basic concepts from here with examples.This concepts are more helpful to learn advance python programming also. 
There are some operations and type conversions in python programs as given below:-
  • Arithmetic operators :-
+, -, *, /, %, //, **
+ --> Addition of two numbers(digits).
e.g.
a=9
b=5
c=a+b
print(c)
Output:-
14

- --> Subtractions of two numbers.
e.g.

a=10
b=5
c=a-b
print(c)
Output:-
5

--> Multiplication of numbers.
e.g.

a=10
b=5
c=4
d=a*b*c
print(d)
Output:-
200
/ --> Division of Two numbers.
a=100
b=5
c=a/b
print(c)
Output:-
20.0

%  --> It returns remainder
e.g.

a=10
b=3
c=a%b
print(c)
Output:-
1

**  --> Exponential operator 

e.g.
base=3
exponent=4
result=base**exponent
print("Exponential value is:",result)
Output:-
Exponential value is: 81
                             OR
Use pow( ) function:-To calculate exponent value on any base ,python uses pow() function.
base=3
exponent=4
result=pow(base,exponent)
print(result)
Output:-
Exponential value is: 81
Note:- To calculate exponent value on base e,python uses exp( ) function.
e--> mathematical constant
e=2.71828 (approx)
First import math module for use exp( )  function in python programs.
Syntax:-
math.exp(exponent)
program:
import math
exponent=4
result=math.exp(exponent)
print (result)

Output:-
54.598150033144236

// -->it returns quotient after discarding fractional part(decimal point).
e.g.
a=50
b=3
c=50//3
print(c)
Output:-
16

  • Compound  assignments operators :-
There are following compound assignments operators used in python programs as shown below:-
+= , -= ,/= , %= , **= , //=
a+=5 : #same as  a=a+5
a-=5 : #same as  a=a-5
a*=5 : #same as  a=a*5
a/=5 : #same as  a=a/5
a**=5 : #same as  a=a^5
a//=5 : #same as  a=a//5

  • Type conversions:- In Python Programs ,we can convert one numeric type to another using built-in function int(),float(),complex(),char(),str() and bool().
1. )   int(float/numeric string)  # from float to int & float to numeric string
e.g.
int(3.5)                             #output: 3
int('786')                           #output: 786
  
2.)  int (numeric string, base)        # from numeric string to int in base
e.g.
  int ('123',10)            #output: 123

3.) Complex(int / float) # convert to complex  with imaginary part 0
e.g.
complex(25)                  #output: 25+0j
complex(25.70)               #output: 25.70+0j

4.) complex(int\float , int/float       # convert to complex 
e.g.
complex(5,7)                     #output 5+7j
complex(5.3,7.5)            #output 5.3+7.5j
complex(5.3,7)                #output 5.3+7j
complex(5,7.5)               #output 5+7.5j

5.) bool(int / float)              # from int/float to True/False (1/0)
e.g.
bool(24)                                  #output True
bool(12.60)                            #output True
bool(1)                                    #output True
bool(0)                                   #output False
bool()                                      #output False
bool(True)                             #output True
bool(False)                            #output False
bool(None)                            #output False

6.) str(int/float/bool)         # convert to string
e.g. 
str(50)                                         #output '50'                        
str(6.4)                                        #output '6.4' 
str(True)                                     #output 'True' 
str(Flase)                                    #output 'False' 

6.) chr(int)                  # convert to Unicode character
e.g.
chr(0)                                        #output '\x00'
chr(5)                                        #output '\x05'
chr(65)                                      #output 'A''
chr(67)                                      #output 'C'
chr(95)                                      #output '-'
chr(125)                                      #output '}'

#Watch Complete Video:-

3

Basic fundamentals of Python part 2

By // No comments:
Python keywords :-
  • Python has 33 keywords that are given below.
  • All keyword in lowercase except(False,None&True)

Note ->
  • keyword is not used as identifier name in the application.
3

Basic fundamentals of Python part 1

By // No comments:
There are following basic fundamentals of python as given below.
  1. Tokens
  2. Comments,Indentation and multi-lining
  3. Python types
  4. Operations and conversions
  5. Built-in functions
  6. Library functions
1.) Tokens :-
  • Token can be defined as a reserved word, punctuation mark and each individual word in a statement .
  • Token is the small unit in the given program.
3

Python Programming Modes

By // No comments:
There are two modes of python programs.
  1. Interactive Modes
  2. Script Modes
1.) Interactive Mode :- 
  • It is used for exploring Python syntax,seek help and debug short programs.
  • Interactive modes uses IDLE (Python Integrated development and Learning Environment).
  • It is available in windows after installation of python setup. Go Start Button--> Search IDLE --> open IDLE python--> It will be opened python shell prompt window-->You can run your python codes from here.
3

How to install Python software on Window Linux Unix and Macintosh operating systems easily

By // No comments:
Hi friends , Today we will learn "How to install python software on window 7,window 8 and window 10 easily".There are many student who are facing problem to install python software on your window 7 ,window vista or window xp. Here we will solve each problems step by steps through our video.You can watch the video and install python software on your window Linux and Macintosh OS easily.  In this tutorial we will solve three type of problems which affects to install the python .
  1. You are not download correct software on the basis of your machine architecture.
  2. Your window 7 or window vista has missing some files.
  3. Your Environment variable path is not set correct in your machine.
3

Learn Python Concepts History Features and its Applications in today real life

By // No comments:
Python is a simple general -purpose, interpreted, interactive, high level and object oriented programming language.
Python was created by Guido Van Rossum during 1985 - 1990. 
This python tutorial is designed for beginners and professionals. Every student and professional can learn  on your home without any institutions.You can learn each concepts of python step by step from here.
  • The idea came for python 1980s.
  • Python start in implementation December 1989s.
  • February 1991 ,Guido Van Rossum published the codes version 0.9.0
  • Guido Van Rossum was born 31 January 1956 in Netherlands.
  • He did the Master’s degree in the mathematics and computer science from University of Amsterdam in 1982.
  • Guido later worked for various research institutes, such as Dutch Centrum Wiskunde & Informatica (CWI), United States National Institute of Standards and Technology (NIST), and also Corporation for National Research Initiatives (CNRI).
  • Python language is derived from two languages

  1. ABC Programming language
  2. Modula-3 language

  • ABC language was also derived from SETL programming language.
  • Guido Added some extra features in python as Exceptional handling concepts Which was early present in ABC language.
  •  Guido worked at Google from 2005 till 7 2012 .
  • Guido joined the cloud file storage company Drop box in 2012.It was surprising to all
  • Python’s name is derived from a television comedy series called “Monty Python’s Flying Circus” according to Guido van Rossum.
  The Python version release dates are as given below:-
3

How to perform Insert Edit Update Delete Cancel and Print Operations in GridView Using Stored Procedure with Example

By // 1 comment:
Hi Friend ,Today we will learn "How to Perform Insert,Edit,Update,Delete and Cancel operations in Gridview Easily".Here I have using Stored Procedure for this operations. This concepts is very good and easy.For this You have to knowledge of Stored Procedure. First we will create Stored Procedure after that use it in different operations in Gridview. For More Knowledge, you have read below link that will be very helpful to you.
There are some steps to implement this whole concepts as given below:-
Step 1 :-First open Open SQL Server Management Studio-->Create a table (Student_Details) with an  identity column as given below:-
3
Powered by Blogger.