0% found this document useful (0 votes)
35 views2 pages

Python 1

The math module in Python provides various mathematical functions, including trigonometric, exponential, logarithmic, power, angular conversion, constants, hyperbolic functions, and other utility functions like ceil and floor. A constructor in Python, defined by the __init__ method, initializes an object's attributes when an instance of a class is created, using parameters passed during instantiation. The constructor allows for setting up initial values for the object's properties.

Uploaded by

shaikhmoin4173
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views2 pages

Python 1

The math module in Python provides various mathematical functions, including trigonometric, exponential, logarithmic, power, angular conversion, constants, hyperbolic functions, and other utility functions like ceil and floor. A constructor in Python, defined by the __init__ method, initializes an object's attributes when an instance of a class is created, using parameters passed during instantiation. The constructor allows for setting up initial values for the object's properties.

Uploaded by

shaikhmoin4173
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Explain the various function of math module

The math module in Python provides access to various mathematical functions for
performing mathematical operations. Here are some of the commonly used functions
in the math module:

1. Trigonometric Functions:
 math.sin(x): Returns the sine of x (x is in radians).
 math.cos(x) : Returns the cosine of x (x is in radians).
 math.tan(x) : Returns the tangent of x (x is in radians).
 math.asin(x) : Returns the arc sine of x (in radians).
 math.acos(x): Returns the arc cosine of x (in radians).
 math.atan(x) : Returns the arc tangent of x (in radians).
2. Exponential and Logarithmic Functions:
 math.exp(x): Returns e raised to the power of x.
 math.log(x, base) : Returns the natural logarithm of x with the specified
base (default base is e).
 math.log2(x) : Returns the base-2 logarithm of x.
 math.log10(x) : Returns the base-10 logarithm of x.
3. Power Functions:
 math.pow(x, y) : Returns x raised to the power of y.
 math.sqrt(x): Returns the square root of x.
4. Angular Conversion:
 math.degrees(x) : Converts angle x from radians to degrees.
 math.radians(x) : Converts angle x from degrees to radians.
5. Constants:
 math.pi: A mathematical constant with the value of π (3.141592...).
 math.e : A mathematical constant with the value of e (2.718281...).
6. Hyperbolic Functions:
 math.sinh(x) : Returns the hyperbolic sine of x.
 math.cosh(x) : Returns the hyperbolic cosine of x.
 math.tanh(x) : Returns the hyperbolic tangent of x.
7. Other Functions:
 math.ceil(x): Returns the smallest integer greater than or equal to x.
 math.floor(x) : Returns the largest integer less than or equal to x.
 math.factorial(x) : Returns the factorial of x.
 math.fabs(x) : Returns the absolute value of x.

write a short note for creating constructor in python ?

In Python, a constructor is a special method that is automatically called when an


object is created. It is used to initialize the object's state. The constructor method in
Python is typically named __init__. It allows you to set up the initial attributes or
properties of an object.

Here is a short note for creating a constructor in Python:

1. Definition: The constructor method __init__ is used to initialize the object's


attributes when an instance of a class is created.
2. Syntax:
pythonCopy code
class ClassName : def __init__ ( self, parameter1, parameter2, ... ): # Initialize
attributes self.parameter1 = parameter1 self.parameter2 = parameter2 ...
3. Parameters:
 self: A reference to the current instance of the class, which allows you
to access the attributes and methods of the class.
 parameter1, parameter2, etc.: Input parameters that are used to
initialize the object's attributes.
4. Usage: When you create an instance of the class, the __init__ method is
automatically called with the specified parameters. It sets the initial values for
the object's attributes.
5. Example:
pythonCopy code
class Person : def __init__ ( self, name, age ): self.name = name self.age = age #
Creating an instance of the Person class person1 = Person( "Alice" , 30 )
print (person1.name) # Output: Alice print (person1.age) # Output: 30

You might also like