It is very annoying and makes code harder to read to have to write math.
before every math function in python. Is there an easy way to make it so we can write just the function name without math.
before them?
Asked
Active
Viewed 582 times
-1

Carla is my name
- 149
- 5
-
what do you mean not write math. Are you asking if you can do math.sqrt() without math but just with sqrt()? – Joe Ferndz Mar 19 '21 at 20:47
-
@mkrieger1 yes, i marked it as duplicate, thanks. – Carla is my name Mar 19 '21 at 20:50
2 Answers
1
You use from <module name> import *
to import all functions or variables within a module. In order to import one specific item, use from <module name> import <to import>
In your case, you would use from math import *
.

llamaking136
- 421
- 5
- 16
0
You can do this:
from math import *
ceil(10.2)
# 11
As Klaus D. suggested in the comments, this doesn't comply with the PEP 8 Style Guide, and I don't encourage you to use it. But I guess it can come in handy, especially if you 're using the interpreter.

Alex Metsai
- 1,837
- 5
- 12
- 24
-
2
-
1I know, but it's what the user asked. Choosing to comply (or not) with PEP 8 is up to the user. – Alex Metsai Mar 19 '21 at 20:48
-
It would have been fine if you would have pointed that out in your answer. – Klaus D. Mar 19 '21 at 20:50
-
Yes it would, so I made an edit but you commented first. Thanks for the suggestion. :D – Alex Metsai Mar 19 '21 at 20:51