Learn python the hard way--ex18

Learn python the hard way–Ex.18

敲的代码如下:

# this one is like your scripts with argv
def print_two (*args):
    arg1, arg2 = args
    print(f"arg1: {arg1}, arg2: {arg2}")

# ok.that *args is actually pointless, we can just do this
def print_two_again (arg1, arg2):
    print(f"arg1: {arg1}, arg2: {arg2}")

# this just takes one argument
def print_one(arg1):
    print(f"arg1: {arg1}")

# this one takes no argements
def print_none():
    print("I got nothin'.")

print_two("Zed","Shaw")
print_two_again("Zed","Shaw")
print_one("First!")
print_none()

教训1:
1.def 一定要顶格写,否则在powershell 运行的时候会报错;
2.函数里第一行要空4格(目的是要格式规整?我试过了5678行也可以正常运行)。

Study drills:
1. Did you start your function definition with def?
-Yes
2. Does your function name have only characters and _ (underscore) characters?
-Yes
3. Did you put an open parenthesis right after the function name?
-Yes.
4. Did you put your arguments after the parenthesis separated by commas?
-Yes.
5. Did you make each argument unique (meaning no duplicated names)?
-Yes.
6. Did you put a close parenthesis and a colon after the arguments?
-Yes.
7. Did you indent all lines of code you want in the function four spaces? No more, no less.
-Yes
8. Did you “end” your function by going back to writing with no indent (dedenting, we call it)?
-Yes
When you run (“use” or “call”) a function, check these things:
1. Did you call/use/run this function by typing its name?
-Yes
2. Did you put the ( character after the name to run it?
-Yes
3. Did you put the values you want into the parentheses separated by commas?
-Yes
4. Did you end the function call with a ) character?
-Yes

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值