学习笔记 DAY1
一 python 2与3的区别
1) print 2.x
print() 3.x
2) raw_input 3.x版本不存在,返回string
input 2.x返回int类型,3.x返回string类型
3) 编码
2.X版本Unicode字符串和非Unicode字符串。Python 3只有一种类型:Unicode
二 模块
1) 密码非明文
import getpass
user=input('input the user name:')
pwd=getpass.getpass('input the password of %s:'%user)
2) os.system(cmd)或os.popen(cmd),前者返回值是脚本的退出状态码,后者的返回值是脚本执行过程中的输出内容
import os
output=os.popen('ls -a')
print(output.read())
三 xrange 用法与 range
>> xrange(5)
xrange(5)
>>> list(xrange(5))
[0, 1, 2, 3, 4]
>>> xrange(1,5)
xrange(1, 5)
>>> list(xrange(1,5))
[1, 2, 3, 4]
>>> xrange(0,6,2)
xrange(0, 6, 2)
>>> list(xrange(0,6,2))
[0, 2, 4]
xrange不是一个list对象,而是一个生成器,不需要一上来就开辟一块很大的内存空间

浙公网安备 33010602011771号