eval:把字符串转换成有效表达式

repr:把有效表达式转换成字符串

round(...)

round(number[, ndigits]) -> number

    Round a number to a given precision in decimal digits (default 0 digits).

    This returns an int when called with one argument, otherwise the

same type as the number. ndigits may be negative.

pow(x, y, z=None, /)

Equivalent to x**y (with two arguments) or x**y % z (with three arguments)

Some types, such as ints, are able to use a more efficient algorithm when

invoked using the three argument form.

class map(object)

 |  map(func, *iterables) --> map object

 |

 |  Make an iterator that computes the function using arguments from

 |  each of the iterables.  Stops when the shortest iterable is exhausted.

>>> a

[1, 2, 3]

>>> b

['a', 'b', 'c']

>>> dict(zip(a,b))

{1: 'a', 2: 'b', 3: 'c'}

>>> mylist.extend([1,2,3])

>>> mylist

[2, 1, 3, 2, 1, 4, 3, 2, 1, 'a', 'a', 1, 2, 3]

>>> mylist.append([1,2,3])

>>> mylist

[2, 1, 3, 2, 1, 4, 3, 2, 1, 'a', 'a', 1, 2, 3, [1, 2, 3]]

-------------------------------------------以上是内置函数------------------------------------------

异常,错误

程序没法处理的任务,会抛出异常

错误一般是,逻辑错误,语法错误,无法生成结果等

>>> a

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

NameError: name 'a' is not defined

>>> 1 / 0

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

ZeroDivisionError: division by zero

>>> if a = b

  File "<stdin>", line 1

    if a = b

         ^

SyntaxError: invalid syntax

>>> b[4]

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

IndexError: list index out of range

python,大部分异常都是基于Exception 这个类

KeyboardInterrupt  Exception  exit

基类 

Exception  

python可以通过 

try语句检测异常:

要检测异常的语句

     except 语句来处理异常:

>>> try:

...     print(a)

... except NameError:

...     print('ABC')

...

ABC

>>> try:

...     print(a)

... except Exception as error:

...     print(error)

...

name 'a' is not defined

try:

   要检测异常的语句

except 检测的异常(如果我们使用Execption)则是捕捉所有异常:#但是不建议大家这么做,因为有些异常是我们需要去真实看到的,

   执行捕获异常之后的事情

else:

用来在没有任何异常情况下执行这里的内容

finally:

   不管异常是否发生,这里面写的语句都会执行

我们一般用来关闭socket,关闭文件,回收线程,进程创建释放,数据库连接,mysql句柄,做一些对象内存释放的工作,

>>> try:

...     print(a)

... except Exception:

...     print('abc')

... else:

...     print('--------')

... finally:

...     print('********')

...

abc

********

raise 可以抛出异常

断言

assert当判断的语句为false 那么会抛出一个AssertionError 异常

断言一般用来判断一些bool语句,在断言成功时不采取任何措施,否则触发AssertionError(断言错误)的异常,

try:

assert 1 == 0

except AssertionError:

print('not equal')

with语句,with语句其实和tryfinally语句是一样的,只不过,他只对支持上下文管理协议context

management protocol,比如我们的mysql链接数据库,会在完成业务之后他有关闭,打开文件也会有关闭文件,

close()

我们通过with语句打开一个文件对象,如果没有出错,文件对象就是file

之后我们做的一系列操作不论是否会发生错误,抛出异常,都会执行内存清理的语句,刷新缓冲区,关闭文件等

-----------------------------------------------异常------------------------------------------------

最新文章

  1. &lt;2016-1-28&gt;
  2. SEO技巧汇集
  3. 20160220 - JavaScript for OS X Automation 调试技巧
  4. [Python模式]策略模式
  5. IMX6输出可控PWM
  6. Crashing Robots(imitate)
  7. codeforces 711C Coloring Trees(DP)
  8. 外星人的供给站 (区间覆盖 t贪心)
  9. DevExpress GridView使用技巧之列标题点击事件
  10. 【VBA研究】VBA通过HTTP协议实现邮件轨迹跟踪查询
  11. Android 项目开发
  12. 【常见踩坑】USB调试安装失败(Installation failed with message INSTALL_CANCELED_BY_USER)
  13. Spring boot——logback 基础使用篇(一)
  14. 转://11g之后,通过v$wait_chains视图诊断数据库hang和Contention
  15. LINQ更新提示找不到行或行已更改的解决一例
  16. rabbit基本原理 转
  17. linux内存源码分析 - 内存池
  18. python添加、修改、删除、访问类对象属性的2种方法
  19. CentOS 下用 Nginx 和 uwsgi 部署 flask 项目
  20. C# Chart使用总结 2 ----属性

热门文章

  1. Linux上安装pip以及setuptools
  2. django组件之ContentType
  3. 在django项目中手动模拟实现settings的配置
  4. 对android的认识
  5. Object-Detection中常用的概念解析
  6. maven加载第三方jar包
  7. (2.4)备份与还原--WAL与备份原理
  8. 注册表REG文件编写大全
  9. IntelliJ IDEA的几个常用快捷键
  10. 使用stringstream格式化字符串