目录
1.环境描述
python3 版本 python3.7
python2 版本 python2.2
2.python3与python2 语法的区别
2.1 print打印内容到文件中
#python3
f=open('./test','w')
print('hello world',file=f)
print('hello world second',file=f)
#python2
f=open('./test','w')
print >> f,'hello world'
2.2 print打印到一行
#python3 打印内容到同一行
x='hello'
for r in x:
print(r,end=' ')
r = r[1:]
#python2 打印内容到同一行
x='hello'
for r in x:
print r,
r=r[1:]
2.3 内置作用域
内置作用域通常称为内置模块,在python启动的时候就已经导入的一些应用函数、变量等
python2 版本是import __builtin__
python3 版本是import builtins
如图:
2.3 iter() 内置方法使用
python2 D={'a':1,'b':2} t=iter(D) t.next() 迭代获取值
python3 D={'a':1,'b':2} t=iter(D) next(t) 迭代获取值