Learn Python the Hard Way 练习
****TABLE OF CONTENTS Preface The Hard Way Is Easier Ex0: The Setup Ex1: A Good First Program Ex2: Comments And Pound Characters Ex3: Numbers And Math Ex4: Variables And Names Ex5: More Variables And Printing Ex6: Strings And Text Ex7: More Printing Ex8: Printing, Printing Ex9: Printing, Printing, Printing Ex10: What Was That? Ex11: Asking Questions Ex12: Prompting People Ex13: Parameters, Unpacking, Variables Ex14: Prompting And Passing Ex15: Reading Files Ex16: Reading And Writing Files Ex17: More Files Ex18: Names, Variables, Code, Functions
- 函数给一段代码命名,类似于以前将一段字符串(EX6)或数字(EX4)定义为一个变量
- 函数读取参数( argument 实参 )的过程,类似于以前一段脚本读取
argv
的方式(EX13, 不同的是在函数中可以跳过参数argument
解包的过程)。 - 可以通过使用1和2的方式,定义最小脚本或者最小命令。
- 函数定义( define )是以
def
结尾吗? - 函数名称是以字符和下划线
_
组成吗? - 函数名称是否紧跟着括号
(
? - 括号里是否包含参数,多个参数之间是否以逗号
,
隔开? - 参数名称是否有重复?(不能使用重复的参数名) 「问题:是某个函数内部的参数名称不能重复还是所有函数间的参数名称都不能重复呢?」
- 紧跟着参数名称的是否括号和冒号
):
? - 函数定义下一行是采用4个空格缩进吗(
indent
)? - 函数结束的位置是否取消了缩进(
dedent
)?
- 调用函数时是否使用了函数的名称?
- 函数名称是否近跟着括号
(
? - 括号后有无参数?多个参数是否用逗号
,
隔开? - 函数是否以括号
)
结尾?
Ex19: Functions And Variables Ex20: Functions And Files Ex21: Functions Can Return Something Ex22: What Do You Know So Far? Ex23: Read Some Code Ex24: More Practice Ex25: Even More Practice Ex26: Congratulations, Take A Test! Ex27: Memorizing Logic Ex28: Boolean Practice Ex29: What If Ex30: Else And If Ex31: Making Decisions Ex32: Loops And Lists Ex33: While Loops Ex34: Accessing Elements Of Lists Ex35: Branches and Functions Ex36: Designing and Debugging Ex37: Symbol Review Ex38: Doing Things To Lists Ex39: Dictionaries, Oh Lovely Dictionaries Ex40: Modules, Classes, And Objects Ex41: Learning To Speak Object Oriented Ex42: Is-A, Has-A, Objects, and Classes Ex43: Gothons From Planet Percal #25 Ex44: Inheritance Vs. Composition Ex45: You Make A Game Ex46: A Project Skeleton Ex47: Automated Testing Ex48: Advanced User Input Ex49: Making Sentences Ex50: Your First Website Ex51: Getting Input From A Browser Ex52: The Start Of Your Web Game Advice From An Old Programmer Next Steps Appendix A: Command Line Crash Course