python常用语法和示例_from关键字和Python中的示例

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常用语法和示例

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值