In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use the basic module of Python". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the basic module of Python".
1. Import of module
There are three ways:
First: import module name
The second type: import module name as new name
The third type: from module name import function name
Import math # the first way
Import numpy as np # the second way
Import matplotlib as mpl # the second way
# import matplotlib.pyplot as plt
From matplotlib import pyplot as plt # the third way
# import seaborn
Def calc_e_small (x):
N = 10
F = np.arange (1, n = 1) .cumprod ()
B = np.array ([x] * n) .cumprod ()
Return np.sum (b / f) + 1
Def calc_e (x):
Reverse = False
If x < 0: # handles negative numbers
X =-x
Reverse = True
Ln2 = 0.69314718055994530941723212145818
C = x / ln2
A = int (cis 0.5)
B = x-a*ln2
Y = (2 * * a) * calc_e_small (b)
If reverse:
Return 1/y
Return y
If _ name__ = = "_ _ main__":
T1 = np.linspace (- 2,0,10, endpoint=False)
T2 = np.linspace (0,4,20)
T = np.concatenate ((T1, T2))
Print (t) # horizontal axis data
Y = np.empty_like (t)
For I, x in enumerate (t):
Y [I] = calc_e (x)
Print ('e ^', x,'=', y [I],'(approximate)\ tasking, math.exp (x),'(true value)')
Plt.figure (facecolor='w')
Mpl.rcParams ['font.sans-serif'] = [' SimHei']
Mpl.rcParams ['axes.unicode_minus'] = False
Plt.plot (t, y, 'rMurray, t, y, 'go', linewidth=2, markeredgecolor='k')
Plt.title (Application of Taylor expansion-exponential function, fontsize=18)
Plt.xlabel ('Xerox, fontsize=15) how much is the http://www.zykdyjyy.com/ of Zhengzhou expelling birthmark Hospital
Plt.ylabel ('exp (X)', fontsize=15)
Plt.grid (True, ls=':')
Plt.show ()
2.if name = = "main" statement
Python is a scripting language. Unlike compiled languages, programs are compiled into binary and then run, but are dynamically interpreted line by line. That is, to run from the first line of the script, there is no unified entry.
When there is this sentence in a Python file, it is like the main function main in C language, where the program starts. This statement prevents some statements in the imported file under the current file from being executed by the line-by-line mechanism of Python.
Because if a .py file (module) is run directly, its _ _ name__ value is _ _ main__, that is, the module name is _ _ main__.
So, if name = 'main' means that when the .py file is run directly, the code block under if name =' main' will be run; when the .py file is imported as a module, the code block under if name = 'main' will not be run.
Thank you for reading, the above is the content of "how to use the Python basic module". After the study of this article, I believe you have a deeper understanding of how to use the Python basic module, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.