python2与python3语法区别(持续更新。。。)

print输出

#py2
print 'd'
#py3
print('d')

#python字典 键值对输出

dict = {}
dict['1one1'] = 'one'
dict[2] = 'two'
#py2
print tinydict.keys()      
# 输出所有键:['1one1', 2]
print tinydict.values()    
# 输出所有值:['one', 'two']
#py3
print (dict.keys())  
#输出: dict_keys(['1one1', 2])
print (tinydict.values())   
#输出:dict_values(['one', 'two'])

#运算符 /

#Python2.x 里,整数除整数,只能得出整数
>>> 1/2
0
>>> 1.0/2
0.5
>>> 1/float(2)
0.5

#python3
a=1/2
print (a) 
0.5

 

你可能感兴趣的:(Python)