在Python中使用示例导入关键字

Python导入关键字 (Python import keyword)

import is a keyword (case-sensitive) in python, it is used in import statement to import module in the program.

import是python中的一个关键字(区分大小写),在import语句中用于在程序中导入模块。

Syntax of import keyword

import关键字的语法

    import module_name

Example:

例:

    import math
    # this statement will import
    # math module in the program

导入关键字的Python示例 (Python examples of import keyword)

Example 1: import math module and call factorial function to calculate the factorial of a given number.

示例1:导入数学模块并调用阶乘函数以计算给定数字的阶乘。

# python code to demonstrate an example 
# of import keyword 

# import statement
import math

# number
num = 5

# finding factorial
result = math.factorial(num)

# printing factorial
print("Factorial of ", num, " is = ", result)

Output

输出量

Factorial of  5  is =  120

Example 2: import datetime module and call its functions to get the current day, month and year.

示例2:导入datetime模块并调用其函数以获取当前的日期,月份和年份。

# python code to demonstrate an example 
# of import keyword 

# import statement
import datetime

# creating date object
dt = datetime.datetime.now()

# printing day, month and year
print("Current day  : ", dt.day)
print("Current month: ", dt.month)
print("Current year : ", dt.year)

Output

输出量

Current day  :  15
Current month:  4
Current year :  2019


翻译自: https://www.includehelp.com/python/import-keyword-with-example.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值