python學習筆記--list

python3 -V 顯示python版本。


使用idle來完成實驗代碼,有提示等多項功能。


alt+p前一條指令
alt+n後一條指令


chapters=["list",'share your code','file and except','storage',
 'handle data','class','web develop','mobile application',
 'handle input','real web develop','handle complexity',
 'others']
print (chapters)


列表最後項加逗號不會默認生成一個空值而是會直接忽略掉


python的變量標識符沒有類型,也就是列表裏可以嵌套列表。


訪問列表數據
print (chapters[0])


查看列表方法
help(list)
pop有返回值


chapters=['1',"list",
 '2','share your code',
 '3','file and except',
 '4','storage',
 '5','handle data',
 '6','class',
 '7','web develop',
 '8','mobile application',
 '9','handle input',
 '10','real web develop',
 '11','handle complexity',
 '12','others']


迭代
for each in chapters:
print(each)


nested lists:
chapters=[
 ['1',"list"],
 ['2','share your code'],
 ['3','file and except'],
 ['4','storage'],
 ['5','handle data'],
 ['6','class'],
 ['7','web develop'],
 ['8','mobile application'],
 ['9','handle input'],
 ['10','real web develop'],
 ['11','handle complexity'],
 ['12','others']
 ]

print(chapters[0][1])

chapters=["python",
 ['1',"list"],
 ['2','share your code'],
 ['3','file and except'],
 ['4','storage'],
 ['5','handle data'],
 ['6','class'],
 ['7','web develop'],
 ['8','mobile application'],
 ['9','handle input'],
 ['10','real web develop'],
 ['11','handle complexity'],
 ['12','others']
 ]


for each in chapters:
print(each)

for each in chapters:
if isinstance(each,list):
for each in each:
print(each)
else:
print(each)

查看bif:

dir(__builtins__)

bif=built in function 


help(dir)


dir(...)
    dir([object]) -> list of strings
    
    If called without an argument, return the names in the current scope.
    Else, return an alphabetized list of names comprising (some of) the attribut


創建函數:

def print_hello(arg):
print("hello"+arg)

def print_x_y():
print("x""y")










發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章