使用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
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")