参考链接: Python中的数学函数 4(特殊函数和常量)

一、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更新后,关键字中加入了异步关键字async和await。

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

二、Python内置函数(库)

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

在命令行中输入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.

第二种方法是,如果使用ipython交互环境,可以直接使用 func + ? 的方式获得帮助

In [8]: time?

Out[9]:

Docstring:

Time execution of a Python statement or expression.

The CPU and wall clock times are printed, and the value of the

expression (if any) is returned.  Note that under Win32, system time

is always reported as 0, since it can not be measured.

This function can be used both as a line and cell magic:

- In line mode you can time a single-line statement (though multiple

ones can be chained with using semicolons).

- In cell mode, you can time the cell body (a directly

following statement raises an error).

This function provides very basic timing functionality.  Use the timeit

magic for more control over the measurement.

.. versionchanged:: 7.3

User variables are no longer expanded,

the magic line is always left unmodified.

Examples

--------

::

In [1]: %time 2**128

CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s

Wall time: 0.00

Out[1]: 340282366920938463463374607431768211456L

:

In [13]: math.sin?

Signature: math.sin(x, /)

Docstring: Return the sine of x (measured in radians).

Type:      builtin_function_or_method

有了这个,可以很快地查看帮助文档而不是网上搜索辣。

使用dir(__builtins__)

In [14]: dir(__builtins__)

Out[14]:

['ArithmeticError',

'AssertionError',

'AttributeError',

'BaseException',

'BlockingIOError',

'BrokenPipeError',

'BufferError',

'BytesWarning',

'ChildProcessError',

'ConnectionAbortedError',

'ConnectionError',

'ConnectionRefusedError',

'ConnectionResetError',

'DeprecationWarning',

'EOFError',

'Ellipsis',

'EnvironmentError',

'Exception',

'False',

'FileExistsError',

'FileNotFoundError',

'FloatingPointError',

'FutureWarning',

'GeneratorExit',

'IOError',

'ImportError',

'ImportWarning',

'IndentationError',

'IndexError',

'InterruptedError',

'IsADirectoryError',

'KeyError',

'KeyboardInterrupt',

'LookupError',

'MemoryError',

'ModuleNotFoundError',

'NameError',

'None',

'NotADirectoryError',

'NotImplemented',

'NotImplementedError',

'OSError',

'OverflowError',

'PendingDeprecationWarning',

'PermissionError',

'ProcessLookupError',

'RecursionError',

'ReferenceError',

'ResourceWarning',

'RuntimeError',

'RuntimeWarning',

'StopAsyncIteration',

'StopIteration',

'SyntaxError',

'SyntaxWarning',

'SystemError',

'SystemExit',

'TabError',

'TimeoutError',

'True',

'TypeError',

'UnboundLocalError',

'UnicodeDecodeError',

'UnicodeEncodeError',

'UnicodeError',

'UnicodeTranslateError',

'UnicodeWarning',

'UserWarning',

'ValueError',

'Warning',

'ZeroDivisionError',

'__IPYTHON__',

'__build_class__',

'__debug__',

'__doc__',

'__import__',

'__loader__',

'__name__',

'__package__',

'__spec__',

'abs',

'all',

'any',

'ascii',

'bin',

'bool',

'breakpoint',

'bytearray',

'bytes',

'callable',

'chr',

'classmethod',

'compile',

'complex',

'copyright',

'credits',

'delattr',

'dict',

'dir',

'display',

'divmod',

'enumerate',

'eval',

'exec',

'filter',

'float',

'format',

'frozenset',

'get_ipython',

'getattr',

'globals',

'hasattr',

'hash',

'help',

'hex',

'id',

'input',

'int',

'isinstance',

'issubclass',

'iter',

'len',

'license',

'list',

'locals',

'map',

'max',

'memoryview',

'min',

'next',

'object',

'oct',

'open',

'ord',

'pow',

'print',

'property',

'range',

'repr',

'reversed',

'round',

'set',

'setattr',

'slice',

'sorted',

'staticmethod',

'str',

'sum',

'super',

'tuple',

'type',

'vars',

'zip']

三、Python的常用内置函数

1. 类型转换和判断

类型转换

In [20]: bin(55) #转换为二进制

Out[20]: '0b110111'

In [21]: oct(33) #转换为八进制

Out[21]: '0o41'

In [22]: hex(114514) #转换为十六进制

Out[22]: '0x1bf52'

In [23]: int('123') #转换为整数

Out[23]: 123

In [24]: int('0xff2', 16) #转换十六进制数字符串,要加上16参数

Out[24]: 4082

In [25]: float(3) #转换成浮点数

Out[25]: 3.0

In [26]: complex(3,4) #按照实部和虚部生成复数

Out[26]: (3+4j)

In [27]: ord('野') #转换字符为unicode编码

Out[27]: 37326

In [28]: chr(114514) #得到数字对应的Unicode字符

Out[28]: '\U0001bf52'

In [29]: str([1,2,3]) #转换其他类型为字符串类型

Out[29]: '[1, 2, 3]'

In [30]: ascii('A') #获得字符的Ascii编码

Out[30]: "'A'"

In [31]: type('sss') #获得某个变量或者常量的类型

Out[31]: str

2. 基本输入输出

>>>print('name{}'.format(3+1))

name4

>>>t = input('请输入一个数字')

请输入一个数字1

>>>print(t)

1

使用print函数默认是换行的,如果不想换行,可以设置参数

In [2]: for i in range(1000,1050):

...:     print(chr(i), end='')

...:

ϨϩϪϫϬϭϮϯϰϱϲϳϴϵ϶ϷϸϹϺϻϼϽϾϿЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙ

3. 将字符串转换成可执行命令

函数eval()提供了将字符串转换成可执行命令的功能

In [3]: eval('1 + 2')

Out[3]: 3

In [4]: eval('print("name")')

name

[转载] (三)Python关键字和内置函数相关推荐

  1. Python中的关键字和内置函数

    Python中所有的关键字(共有33个关键字): Python中所有的内置函数: 注意 在Python 2.7中, print是关键字而不是函数.另外, Python 3没有内置函数unicode() ...

  2. python中比较重要的几个函数_Python 几个重要的内置函数 python中的内置函数和关键字需要背过吗...

    python重要的几个内置函数用法 python内置函数什么用忘不掉的是回忆,继续的是生活,错过的,就当是路过吧.来来往往身边出现很多人,总有一个位置,一直没有变.看看温暖的阳光,偶尔还是会想一想. ...

  3. python之路——内置函数和匿名函数

    楔子 在讲新知识之前,我们先来复习复习函数的基础知识. 问:函数怎么调用? 函数名() 如果你们这么说...那你们就对了!好了记住这个事儿别给忘记了,咱们继续谈下一话题... 来你们在自己的环境里打印 ...

  4. Python两个内置函数——locals 和globals

    python作用域 http://tgstdj.blog.163.com/blog/static/748200402012419114428813/ 有两种类型的作用域--类的变量和对象的变量. 类的 ...

  5. 十五. Python基础(15)--内置函数-1

    十五. Python基础(15)--内置函数-1 1 ● eval(), exec(), compile() 执行字符串数据类型的python代码 检测#import os 'import' in c ...

  6. python学习总结----内置函数及数据持久化

    python学习总结----内置函数及数据持久化 抽象基类(了解)- 说明:- 抽象基类就是为了统一接口而存在的- 它不能进行实例化- 继承自抽象类的子类必须实现抽象基类的抽象方法 - 示例:from ...

  7. Python学习(14)--内置函数

    Python学习(14)--内置函数 1.Python内置函数 在Python中有很多的内置函数供我们调用,熟练的使用这些内置函数可以让编写代码时事半功倍,所谓内置函数就是那些Python已经预定义并 ...

  8. 初学者python笔记(内置函数_2)

    这篇初学者笔记是接着上一篇初学者python笔记(内置函数_1)的.同样都是介绍Python中那些常用内置函数的. max()和min()的高级用法 我们都知道,max():取最大值,min():取最 ...

  9. python提供的内置函数有哪些_python内置函数介绍

    内置函数,一般都是因为使用频率比较频繁,所以通过内置函数的形式提供出来.对内置函数通过分类分析,基本的数据操作有数学运算.逻辑操作.集合操作.字符串操作等. 说起我正式了解内置函数之前,接触到的是la ...

最新文章

  1. linux 共享内存_什么是物理/虚拟/共享内存——Linux内存管理小结一
  2. Windows中EFS加密及解密应用
  3. 可添加至收藏夹并在浏览器地址栏运行的JS代码
  4. PLSQL_性能优化系列10_Oracle Array数据组优化
  5. sprintf()--字串格式化命令
  6. 屏下摄像头技术来了!OPPO FindX2有望率先搭载
  7. 前端知识 | React Native手势响应浅析
  8. python学习图解_大牛整理!Python学习方法和学习路线,看完茅塞顿开!
  9. Spring boot Jar和war运行差异
  10. nodejs 通过 get获取数据修改redis数据
  11. 【程序人生】底层程序员,出局
  12. 理解设计模式中的工厂模式
  13. Oracle 锁表查询
  14. 【工业视觉-CCD相机和CMOS相机成像的本质区别】
  15. 【七里香】雨下整夜 我的爱溢出就像雨水
  16. 第十二章:组播 — PIM-SM
  17. 清新亮丽装饰 88平幸福四口之家
  18. 【K8S】secret来配置K8S应用(环境变量)--20220916
  19. 前后端分离与跨域的解决方案(CORS的原理)
  20. linux系统工程师面试题(附答案)

热门文章

  1. 【CCCC】L3-023 计算图 (30分),dfs搜索+偏导数计算
  2. Lc19删除链表的倒数第N个节点
  3. Coprime Sequence
  4. 有向图的强连通分量--Tarjan算法---代码分析
  5. 在一个请求分页系统中,假定系统分配给一个作业的物理块数为 3,并且此作业的页面走向为 2、3、2、1、5、2、4、5、3、2、5、2。试用 FIFO和 LRU 两种算法分别计算出程序访问过程中所发生
  6. 互联网控制协议ICMP
  7. bzoj 1671: [Usaco2005 Dec]Knights of Ni 骑士(BFS)
  8. 差分滤波器的实现及作用于图像提取图像的特征
  9. matlab 计算矩阵a的离散余弦变换
  10. [GCN] Modification of Graph Convolutional Networks in PyTorch