Python学习第一篇
时间:2011-02-17 来源:jackdesk
counter=0
miles=100.0
name='boob'
counter=counter+1
kilomters=1.609*miles
print '%f miles is the same as %f km' %(miles,kilomters)
atuple[0]='99'
print atuple[0:3]
miles=100.0
name='boob'
counter=counter+1
kilomters=1.609*miles
print '%f miles is the same as %f km' %(miles,kilomters)
输入结果是: 100.000000 miles is the same as 160.900000 km
Python不支持c,C++等语言中的自增1或者自减1只有写成a=a+1;
Python中的字符串支持成对的单引号,双引号,单引号。这个又与常见的C,C++C#不同,字符串使用索引运算符[],或者偏运算符[:] 可以得到子字符串
元组不能修改其内容。比如下列代码:
atuple=('robots',66,'oo','9')atuple[0]='99'
print atuple[0:3]
结果则为报错:
TypeError: 'tuple' object does not support item assignment
相关阅读 更多 +