exercise 22&23 总结+读代码
来源:互联网 发布:淘宝photoshop教程 编辑:程序博客网 时间:2024/05/11 23:24
Here's what you do:
- Go to bitbucket.org, github.com, or gitorious.org with your favorite web browser and search for "python."
- Pick a random project and click on it.
- Click on the Source tab and browse through the list of files and directories until you find a .py file.
- Start at the top and read through the code, taking notes on what you think it does.
- If any symbols or strange words seem to interest you, write them down to research later.
Now try some of these other sites:
- github.com
- launchpad.net
- gitorious.org
- sourceforge.net
总结
1.print 用法:
1)一般情况最后不需加逗号;
2)加逗号表示显示在同一行,不加会自动在新的一行显示
2.%? 格式符用法总结在exercise5
常用的:
%d 格式化整数
%f 格式化浮点数,可以指定小数点后的精度,默认显示6位小数,例如%.2f显示2位小数。
%s 格式化字符串#显示字符串内容
%r 大字符串 #显示字符串 包括字符串前面的""
3.转义字符
\n 换行
\'
\b 退格,表示删除前面一个字符
\t 水平制表符 #作用同tab 4个空格键
\v 垂直制表符,表示换行,然后从\v的地方开始输出。
\n 换行
\f 换页
\r 回车 回到行首
4. 键入 raw_input int(raw_input())用于计算
5. 提示 age = raw_input("How old are you? ")
6. pydoc????????
7.解包变量
from sys import argv #从python功能库中导入功能 “features"真正的名称是:modules / libraries
script, first, second, third = argv # argv是“参数变量”,解变量
8.读取文件
open(路径+文件名,读写模式) w 以写方式打开
f.read()
f.close()
f.seek(0/1/2) #0代表从头开始,1代表当前位置,2代表文件最末尾位置。
9.exercise17有点模糊 怎么到to_file的???
10. echo 将内容写入某文件
cat 显示某文件(txt?)
11. from os.path import exists (专门有os.path 模块介绍) ##从os.path模块中导入exists命令
12.定义函数
def print_two(*args): #给函数定义了一个变量组???*args
arg1, arg2 = args
arg1, arg2 = args
def function(valuables): ###def 最后是引号!!!!
------
return ----- ##函数能返回信息
13.raw_input &input
1)这两个函数均能接收字符串,但 raw_input() 直接读取控制台的输入(任何类型的输入它都可以接收)。
而对于 input() ,它希望能够读取一个合法的 python 表达式,即你输入字符串的时候必须使用引号将它括起来,否则它会引发一个 SyntaxError 。
2)raw_input() 将所有输入作为字符串看待,返回字符串类型。而 input() 在对待纯数字输入时具有自己的特性,它返回所输入的数字的类型 int, float。
除非对 input() 有特别需要,否则一般情况下我们都是推荐使用 raw_input() 来与用户交互。
14. with as
普通代码如下:
但可能产生问题:一是可能忘记关闭文件句柄;二是文件读取数据发生异常,没有进行任何处理。
下面是用try——finally来处理异常的加强版本:
简短版本:
基本思想是with所求值的对象必须有一个__enter__()方法,一个__exit__()方法。
紧跟with后面的语句被求值后,返回对象的__enter__()方法被调用,这个方法的返回值将被赋值给as后面的变量。当with后面的代码块全部被执行完之后,将调用前面返回对象的__exit__()方法。
????????
0 0
- exercise 22&23 总结+读代码
- Exercise 23:阅读一些代码
- Exercise:Vectorization 代码示例
- 全部exercise的总结
- Exercise:Sparse Autoencoder 代码示例
- Exercise:Softmax Regression 代码示例
- Exercise:Sparse Autoencoder 代码示例
- linux exercise 22
- Exercise(23):打印沙漏
- linux exercise 23
- Exercise 15:读文件
- Exercise
- exercise
- Exercise
- exercise
- Exercise 18:命名,变量,代码,函数
- Exercise:PCA in 2D 代码示例
- Exercise:PCA and Whitening 代码示例
- CentOS7 groupinstall 桌面 失败
- ZigZag Conversion
- 解决Code::Blocks导入主题时,找不到default.conf的解决办法
- 安装RPM包包错总结
- 堆管理-malloc,calloc,realloc函数之间的区别
- exercise 22&23 总结+读代码
- Ubuntu中ELK安装和调试的一些要点
- Mfc程序窗体在屏幕中的位置和窗体宽和长
- 传输层01
- 关于OpenQuant试用软件的期限的延长问题...如何解决 OpenQuant 过期的问题
- 属性动画资料文件如何编写?property-animation资源文件 属性动画如何自定义TypeEvaluator
- Android 系列 5.7使用Google ZXing条形码扫描器扫描条形码或QR码
- ios的 UIButton
- android 如何拨打暗码进入app