笨办法学py 38-39

lesson 阅读代码
然后通读你打印出来的代码并做好标记,标记的内容包括以下几个方面:
1,函数以及函数的功能。
2,每个变量的初始赋值。
3,每个在程序的各个部分中多次出现的变量。它们以后可能会给你带来麻烦。
4,任何不包含else的if语句。它们是正确的吗?
5、任何可能没有结束点的while循环。
6,最后一条,代码中任何你看不懂的部分都记下来。

lesson 39

ten_things = "Apples Oranges Crows Telephone Light Sugar"
print("Wait there's not 10 things in that list, let's fix that")
stuff = ten_things.split(' ')
more_stuff = ["Day", "Night", "Song", "Frisbee", "Corn","Banana", "Girl", "Boy"]
while len(stuff)!=10:
    next_one = more_stuff.pop()
    print("adding:",next_one)
    stuff.append(next_one)
    print("there's %d items now."%len(stuff))
运行的结果
print("there we go:",stuff)
print("let's do some things with stuff.")
print(stuff[1])
print(stuff[-1])
print(stuff.pop())
print(''.join(stuff))
print('#'.join(stuff[3:5]))
Wait there's not 10 things in that list, let's fix that
adding: Boy
there's 7 items now.
adding: Girl
there's 8 items now.
adding: Banana
there's 9 items now.
adding: Corn
there's 10 items now.
there we go: ['Apples', 'Oranges', 'Crows', 'Telephone', 'Light', 'Sugar', 'Boy', 'Girl', 'Banana', 'Corn']
let's do some things with stuff.
Oranges
Corn
Corn
ApplesOrangesCrowsTelephoneLightSugarBoyGirlBanana
Telephone#Light

1,将每一个被调用的函数以上述的方式翻译成Python实际执行的动作。例如:’’.join(things)其实是join(’’,things)。
2,将这两种方式翻译为自然语言。例如,.’.join(things)可以翻译成"用“连接(join)things",而join(’’,things)的意思是“为…和things调用join函数”。这其实是同一件事情。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值