KEMBAR78
Python Math Functions CheatSheet | PDF
0% found this document useful (0 votes)
16 views1 page

Python Math Functions CheatSheet

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

Python Math Functions CheatSheet

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

■ Python Math Functions Cheat Sheet

Python provides built-in math functions and a math module for advanced operations. Use import
math to access more functions.

■ Built-in Math Functions


Function Description Example

abs(x) Absolute value abs(-5) → 5


round(x) Rounds to nearest integer round(3.6) → 4
pow(x, y) x raised to power y pow(2, 3) → 8
max(x, y, ...) Largest of values max(1, 3, 2) → 3
min(x, y, ...) Smallest of values min(1, 3, 2) → 1
sum(iterable) Sum of elements sum([1, 2, 3]) → 6

■ Math Module Functions (need import math)


Function Description Example

math.sqrt(x) Square root math.sqrt(16) → 4.0


math.ceil(x) Ceiling (round up) math.ceil(3.2) → 4
math.floor(x) Floor (round down) math.floor(3.9) → 3
math.fabs(x) Absolute (float) math.fabs(-7.5) → 7.5
math.factorial(x) Factorial math.factorial(5) → 120
math.pi PI constant math.pi → 3.1415...

Example:
import math x = -9 print(abs(x)) # 9 print(math.sqrt(25)) # 5.0 print(round(3.1415, 2)) # 3.14

You might also like