(三)Python关键字和内置函数

本文介绍了Python的关键字,强调了它们的特殊含义和不可用作标识符的特性。此外,详细阐述了Python内置函数的使用,包括通过命令行查看函数文档的方法。还重点讲解了常用的内置函数,如类型转换、基本输入输出以及如何将字符串转化为可执行命令。
摘要由CSDN通过智能技术生成

一、Python的关键字

和其他语言一样,关键字有特殊含义,并且关键字不能作为变量名、函数名、类名等标识符。
快速查看关键字的方法除了上csdn和百度搜索外,还可以在命令行交互环境中查看

>>> from keyword import kwlist
>>> print(kwlist)
['False', 'None', 'True', 'and',
 'as', 'assert', 'async', 'await', 
 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 
'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 
'is', 'lambda', 'nonlocal', 'not', 
'or', 'pass', 'raise', 'return', 
'try', 'while', 'with', 'yield'
]

在python3.5更新后,关键字中加入了异步关键字asyncawait

这些关键字在各个章节中会介绍。

二、Python内置函数(库)

了解python内置函数的使用(扩展库,自定义函数、库),都可以这样做

  1. 在命令行中输入help('func'),参数为函数名的字符串,会显示相关库、函数、类等的文档
>>>help('math') #数学运算库的文档

Help on module math:

NAME
    math

MODULE REFERENCE
    https://docs.python.org/3.7/library/math
    
    The following documentation is automatically generated from the Python
    source files.  It may be incomplete, incorrect or include features that
    are considered implementation detail and may vary between Python
    implementations.  When in doubt, consult the module reference at the
    location listed above.

DESCRIPTION
    This module provides access to the mathematical functions
    defined by the C standard.

FUNCTIONS
    acos(x, /)
        Return the arc cosine (measured in radians) of x.
    
    acosh(x, /)
        Return the inverse hyperbolic cosine of x.
    
    asin(x, /)
        Return the arc sine (measured in radians) of x.
    
    asinh(x, /)
        Return the inverse hyperbolic sine of x.
:
#节选了文档中的一部分内容

>>>help('abs') #绝对值函数的说明

Help on built-in function abs in module builtins:
abs(x, /)
    Return the absolute value of the argument.

  1. 第二种方法是,如果使用ipython交互环境,可以直接使用
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值