初识Python

列表:
1 num=['One','Two','Three']           #[]内表示一个列表,列表可以容纳任何类型元素
2   print(num[1])
3 nums=['One_1','One_2','One_3',['Two_1','Two_2',['Three_1','Three_2','Three_3']]]
4                           #多列表嵌套,nums[3][2][2]=Three3
迭代:
1 for each in num:
2     print(each)
3 count=0                        #使用变量前要对其赋值
4 while count
5   print(num[count])
6   count=count+1

  函数:

1 def fun (nums,indent=true):
2   #Do something 

  相关BIF函数:

1 len(nums)                           #计算长度
2 num.append('four')                  #列表末尾增加一个数据项
3 num.pop()                           #列表末尾删除一个数据项
4 num.extend(['six','seven'])         #列表末尾增加一个数据项集合
5 num.remove('One')                   #在列表中找到并删除一个特定的数据项
6 num.insert(0,'zero')                #在某个特定的位置前面增加一个数据项
7 isinstance(num,list)                #list为列表类型,检查num是否为list,返回布尔类型值
8 dir(__builtins__)                   #显示所有BIF shell中使用
9 help(input)                         #显示该BIF的功能描述

 

posted @ 2013-11-03 19:38  Code__Monkey  阅读(121)  评论(0)    收藏  举报