#15 Python Tutorial for Beginners | Import Math Functions in Python

#15 Python Tutorial for Beginners | Import Math Functions in Python

Python Math Functions

In this video, the presenter discusses Python's mathematical functions and how to use them. The video covers finding square roots, using the float function, using the power function, and accessing constants like pi.

Finding Square Roots

  • To find a square root of a number in Python, use the built-in sqrt function from the math module.
  • Importing the math module is necessary before using its functions.
  • Use math.sqrt(number) to find the square root of a number.
  • Example: X = math.sqrt(25) will give you 5.0 as X.

Using Float Function

  • The float function can be used to round down any decimal value to an integer.
  • Example: float(2.9) will return 2.

Using Power Function

  • The power function can be used to raise a number to a certain power.
  • Two ways of doing this are by using double stars or by calling the built-in pow() function from the math module.
  • Example: math.pow(3, 2) or 3 ** 2 both return 9.

Accessing Constants

  • The math module also provides access to some useful constants such as pi.
  • To access pi in Python, use math.pi.
  • Example: printing out math.pi will give you approximately 3.141592653589793.

Using Aliases in Python

In this section, the speaker explains how to use aliases in Python to avoid typing long module names repeatedly.

Importing Modules with Long Names

  • When importing modules with long names, it can be tedious to type out the full name every time.
  • Aliases can be used to shorten the name of a module when importing it.
  • For example, instead of typing import math every time, you can use an alias like import math as m.

Using Aliases for Specific Functions

  • If you only need specific functions from a module, you can import them using aliases as well.
  • For example, if you only need the square root and power functions from the math module, you can import them like this: from math import sqrt, pow.
  • This allows you to use these specific functions without having to type out the full module name or import all of its functions.

Importing Specific Functions from Modules

In this section, the speaker explains how to import specific functions from modules in Python.

Importing Specific Functions

  • To import specific functions from a module in Python, use the syntax from <module> import <function1>, <function2>, ....
  • This allows you to only import the necessary functions and not clutter your code with unused ones.
  • Once imported, these functions can be used directly without having to reference their parent module.
Video description

Check out our courses: AI Powered DevOps with AWS - Live Course :- https://go.telusko.com/AIDevOps-AWS Coupon: TELUSKO10 (10% Discount) Complete Java Developer Course Batch-4: https://go.telusko.com/Complete4 Coupon: TELUSKO10 (10% Discount) Master Java Spring Development : https://go.telusko.com/masterjava Coupon: TELUSKO20 (20% Discount) Udemy Courses: Spring: https://go.telusko.com/udemyteluskospring Java:- https://go.telusko.com/udemyteluskojava Java Spring:- https://go.telusko.com/Udemyjavaspring Java For Programmers:- https://go.telusko.com/javaProgrammers Python : https://go.telusko.com/udemyteluskopython Git : https://go.telusko.com/udemyteluskogit Docker : https://go.telusko.com/udemyteluskodocker For More Queries WhatsApp or Call on : +919008963671 website : https://courses.telusko.com/ Instagram : https://www.instagram.com/navinreddyofficial/ Linkedin : https://in.linkedin.com/in/navinreddy20 TELUSKO Android App : https://bit.ly/TeluskoApp In this lecture we are discussing about math function: -- math module in Python provides a wide range of mathematical functions. -- math module is a built-in module in Python. -- math module is used to perform mathematical operations. -- math module is used to perform mathematical operations like square root, power, floor, ceil, etc. -- for using math module we have to import it first # import math -- then we can use math module function like math.sqrt(25) or -- we can use alias name like m=math then we can use m. m.sqrt(25) if we import math as m or -- we can import only required function like from math import sqrt,pow sqrt(25) pow(2,3) Here are some of the most commonly used ones methods of math module: math.sqrt(x): Returns the square root of x. math.pow(x, y): Returns x raised to the power y. 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.exp(x): Returns the exponential value of x. math.log(x[, base]): Returns the natural logarithm (base e) of x or the logarithm of x with the specified base. math.sin(x), math.cos(x), math.tan(x): Returns the trigonometric sine, cosine, or tangent of x, respectively. Here are some of the most commonly used ones attributes(constant) of math module: math.pi: Returns the value of pi. math.e: Returns the value of e. math.inf: Returns a floating point positive infinity. math.nan: Returns a floating point “not a number” (NaN) value. using help function we can get all the information about math module help(math) Github :- https://github.com/navinreddy20/Python- Python for Beginners :- http://bit.ly/3JOLQhl Editing Monitors : https://amzn.to/2RfKWgL https://amzn.to/2Q665JW https://amzn.to/2OUP21a. Java:- https://bit.ly/JavaUdemyTelusko Spring:- https://bit.ly/SpringUdemyTelusko More Learning : Java :- https://bit.ly/3x6rr0N Python :- https://bit.ly/3GRc7JX Django :- https://bit.ly/3MmoJK6 JavaScript :- https://bit.ly/3tiAlHo Node JS :- https://bit.ly/3GT4liq Rest Api :-https://bit.ly/3MjhZwt Servlet :- https://bit.ly/3Q7eA7k Spring Framework :- https://bit.ly/3xi7buh Design Patterns in Java :- https://bit.ly/3MocXiq Docker :- https://bit.ly/3xjWzLA Blockchain Tutorial :- https://bit.ly/3NSbOkc Corda Tutorial:- https://bit.ly/3thbUKa Hyperledger Fabric :- https://bit.ly/38RZCRB NoSQL Tutorial :- https://bit.ly/3aJpRuc Mysql Tutorial :- https://bit.ly/3thpr4L Data Structures using Java :- https://bit.ly/3MuJa7S Git Tutorial :- https://bit.ly/3NXyCPu Donation: PayPal Id : navinreddy20 https://www.telusko.com

#15 Python Tutorial for Beginners | Import Math Functions in Python | YouTube Video Summary | Video Highlight