Python是动态类型语言,也就是不需要预先定义变量类型。变量的类型和值在赋值那一刻被初始化。变量赋值通过符号来执行。例如:

 

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)

 

 

输入结果是: 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

 

 

 

posted on 2011-02-17 22:45  jackdesk  阅读(484)  评论(0编辑  收藏  举报