python常用语法和示例
关键字中的Python (Python from keyword)
from is a keyword (case-sensitive) in python, it is used to import a specific section from a module, like functions, classes, etc.
from是python中的一个关键字(区分大小写),用于从模块中导入特定部分,例如函数,类等。
Syntax of from keyword
from关键字的语法
from module_name import specific_section1, specific_section1, ...
Here, specific_section(s) are the names of functions, classes, etc.
在这里, specific_section是函数,类等的名称。
Example:
例:
# importing factorial from math module
from math import factorial
from关键字的Python示例 (Python examples of from keyword)
Example 1: Find factorial of a number by importing factorial from math module.
示例1:通过从数学模块中导入阶乘来查找数字的阶乘。
# python code to demonstrate example of
# from keyword
# Find factorial of a number
# by importing factorial from math module.
# importing factorial from math module
from math import factorial
num = 4
# printing factorial
print("factorial of ", num, " is = ", factorial(num))
Output
输出量
factorial of 4 is = 24
Example 2: Find factorial and square root of a number by importing two functions factorial and sqrt from math module.
示例2:通过从数学模块中导入两个函数阶乘和平方根来查找数字的阶乘和平方根。
# python code to demonstrate example of
# from keyword
# Find factorial and square root of a number
# by importing two functions factorial and sqrt
# from math module.
# importing factorial and sqrt from math module
from math import factorial, sqrt
num = 4
# printing factorial & square root
print("factorial of ", num, " is = ", factorial(num))
print("square root of ", num, " is = ", sqrt(num))
Output
输出量
factorial of 4 is = 24
square root of 4 is = 2.0
翻译自: https://www.includehelp.com/python/from-keyword-with-example.aspx
python常用语法和示例