Hi, my name is beatbox4108. This time, I would like to write about advanced calculation using __import statement __.
You can use the __import statement __ to execute other python files (.py .pyw).
ʻImport module name: You can refer to it in a python file as
module name. ʻImport module name as reference name
:
You can refer to it in a python file as a reference name
.
from module name import function name
:
Imports the specified function.
from module name import *
:
Import all functions in module name
.
There is a math module in the python standard library, so I would like to import it and use it. Please write like this.
main.py
import math as m
print("Pi:",m.pi)#3.141592653589793
print("3.Round up 5:",m.ceil(3.5))#4
print("3.Devaluation of 5:",m.floor(3.5))#3
print("3 to the 5th power:",m.pow(3,5))#243.0(The power of the math module is returned as a float type. Built-in pow function,**You can also use operators.)
print("Make 180 degrees radians:",m.radians(180))#3.141592653589793
print("180 radians at an angle:",m.degrees(3.141592653589793))#180.0
print("sin 100:",m.sin(100),",cos 100:",m.cos(100),",tan 100",m.tan(100))
#sin 100: -0.5063656411097588 ,cos 100: 0.8623188722876839 ,tan 100 -0.5872139151569291
print("Square root of 9",m.sqrt(9))#3
... you can do it well. Next, I haven't posted the table of arithmetic operators even once, so I'd like to post it.
operator | function | Example | Description |
---|---|---|---|
+(Unary plus operator) | Positive number | +x | Specify a positive number. It does not change even if a code is added. |
-(Unary minus operator) | Sign inversion | -x | Invert the sign of the value of a. |
+ | addition | x + y | Add y to x. |
- | subtraction | x - y | Subtract y from x. |
* | multiplication | x * y | Multiply x by y. |
/ | division | x / y | Divide x by y. |
// | Integer division(If the expression contains a decimal number, it can be of type float.) | x // y | Truncate the decimal from the result of dividing x by y. |
** | multiplier | x**y | Find x to the yth power. |
% | Surplus | x % y | Find the remainder of x divided by y |
This time, I would like to end with this. Stay tuned for the next time! Go to Table of Contents
Recommended Posts