0% found this document useful (0 votes)
144 views1 page

Python Math Functions Overview

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)
144 views1 page

Python Math Functions Overview

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

■ 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

[Link](x) Square root [Link](16) → 4.0


[Link](x) Ceiling (round up) [Link](3.2) → 4
[Link](x) Floor (round down) [Link](3.9) → 3
[Link](x) Absolute (float) [Link](-7.5) → 7.5
[Link](x) Factorial [Link](5) → 120
[Link] PI constant [Link] → 3.1415...

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

You might also like