exercise 37 符号复习-待续
来源:互联网 发布:seo网络营销技术 编辑:程序博客网 时间:2024/06/03 20:24
Keywords
Data Types
For data types, write out what makes up each one. For example, with strings write out how you create a string. For numbers write out a few numbers.
String Escape Sequences
For string escape sequences, use them in strings to make sure they do what you think they do.
String Formats
Same thing for string formats: use them in some strings to know what they do.
Operators
Some of these may be unfamiliar to you, but look them up anyway. Find out what they do, and if you still can't figure it out, save it for later.
新知识点:
1.Assert 用法:
mylist = ['item']assert len(mylist) >= 1 ##此时列表里有一个元素‘item’ 使用assert语句时,语句正确 无报错mylist.pop() ##pop函数默认移除列表中最后一个元素 即将列表中唯一元素删除assert len(mylist) >= 1 ##此时列表为空 长度小于1 语句错误 显示AssertionError
显示
Traceback (most recent call last): File "C:/Users/xhu63/PycharmProjects/untitled/assert.py", line 7, in <module> assert len(mylist) >= 1AssertionError
2.Except 用法:(跟try raise finally 一起处理异常 有点混乱!!!!! 下面网址有所有)
http://www.cnblogs.com/ybwang/archive/2015/08/18/4738621.html
这是应用实例:http://blog.csdn.net/u013088799/article/details/39100881
try: <语句>except <name>: <语句> #如果在try部份引发了名为'name'的异常,则执行这段代码else: <语句> #如果没有异常发生,则执行这段代码
处理异常的三种方法:
1)捕获所有异常
try
:
a
=
b
b
=
c
except
Exception,e:
print
Exception,
":"
,e
2)采用trackback模块查看异常
#引入python中的traceback模块,跟踪错误
import
traceback
try
:
a
=
b
b
=
c
except
:
traceback.print_exc()
3)采用sys模块回溯异常
#引入sys模块
import
sys
try
:
a
=
b
b
=
c
except
:
info
=
sys.exc_info()
print
info[
0
],
":"
,info[
1
]
try: <...............> #可能得到异常的语句except <.......>: #锁定是哪种异常 <...............> #出现异常的处理方法
3. exec 用法:
exec语句用来执行储存在字符串或者文件中的python语句。可以生成一个包含python代码的字符串,然后使用exec语句执行这些语句。
>>>exec 'print "hello word"'hello world
4. yeild用法:
5.finally 用法:
- exercise 37 符号复习-待续
- Exercise 37: 复习各种符号
- Docker 复习 . 常用命令(待续)
- exercise 36 设计和调试-作业待续
- exercise 35 分支和函数-待续
- 练习37——复习符号
- 计算机专业知识复习汇总(待续)
- 笨方法学Python 习题 37: 复习各种符号
- 笨方法学python习题37 (复习各种符号)
- 笨方法学习Python-习题37: 复习各种符号
- 半导体复习-自由电子模型(待续)
- 计算机组成复习 数字电路模块 待续Ing
- Python Exercise #37
- 37-1-2-exercise
- Exercise
- exercise
- Exercise
- exercise
- Angular企业级开发(1)-AngularJS简介
- Shader自学笔记 1.3 使用属性控制渲染效果
- mysql安装问题
- 安装Mysql后利用SQLyogEnt启动是提示“access denied for user 'root'@'localhost'(using password:YES)”
- Linux下运行第一个JAVA程序
- exercise 37 符号复习-待续
- Linux平台总线驱动设备模型
- Yii2 导入导出Excel
- [准确]判断PHP键值数组是否存在,使用empty或isset或array_key_exists
- java多线程concurrent包
- Mac-安装gradle
- [Leetcode] 60. Permutation Sequence 解题报告
- yii2 常用ActiveForm表单样式用法总结
- 火星人永久家园建立在何处?