发布时间:2012-12-27 10:35:52
十一、元组的使用 元组和列表十分类似,只不过元组和字符串一样是不可变的 即你不能修改元组。元组通过圆 括号中用逗号分割的项目定义。元组通常用在使语句或用户定义的函数能够安全地采用一组值 的时候,即被使用的元组的值不会改变 zoo = ('wolf', 'elephant', 'penguin') #使用圆括号来添加成员的 print 'Number of animals in the zoo is', len(zoo) new_zoo = ('monkey', 'dolphin', zoo)......【阅读全文】
发布时间:2012-12-27 10:21:26
六、向数组中添加内容append shoplist = ['apple', 'mango', 'carrot', 'banana'] print 'I have', len(shoplist),'items to purchase.' print 'These items are:', # Notice the comma at end of the line for item in shoplist: # 遍历数组使用的是 for item in shoplist &nb......【阅读全文】
发布时间:2012-12-27 09:22:21
一、python中的List: Example 3.25. key s, values 和 i tems 函数 >>> params = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"} >>> params.keys() (1) ['server', 'uid', 'database', 'pwd'] >>> params.......【阅读全文】
发布时间:2012-12-27 09:17:17
单引号和双引号: 在双引号中的字符串与单引号中的字符串的使用完全相同使用三引号('''或"""): 利用三引号,你可以指示一个多行的字符串。你可以在三引号中自由的使用单引号和双引号。 例如: '''This is a multi-line string. This is the first line. This is the second line. "What's your name?," I asked. He said "Bond, James Bond." '''转义符: 'What\'s you name' (注意要加上\来转义'不然python会不认识')级......【阅读全文】