Skip to content

gabriel-guobin/python0

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python0

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

Ex18: Names, Variables, Code, Functions

函数可以做以下三件事:(与以前操作过的旧知识点建立联系)

  1. 函数给一段代码命名,类似于以前将一段字符串(EX6)或数字(EX4)定义为一个变量
  2. 函数读取参数( argument 实参 )的过程,类似于以前一段脚本读取argv的方式(EX13, 不同的是在函数中可以跳过参数 argument 解包的过程)。
  3. 可以通过使用1和2的方式,定义最小脚本或者最小命令。

定义函数的注意事项

  1. 函数定义( define )是以def结尾吗?
  2. 函数名称是以字符和下划线_组成吗?
  3. 函数名称是否紧跟着括号(?
  4. 括号里是否包含参数,多个参数之间是否以逗号,隔开?
  5. 参数名称是否有重复?(不能使用重复的参数名) 「问题:是某个函数内部的参数名称不能重复还是所有函数间的参数名称都不能重复呢?」
  6. 紧跟着参数名称的是否括号和冒号):?
  7. 函数定义下一行是采用4个空格缩进吗(indent )?
  8. 函数结束的位置是否取消了缩进(dedent)?

运行(run/call/use )函数的注意事项

  1. 调用函数时是否使用了函数的名称?
  2. 函数名称是否近跟着括号(?
  3. 括号后有无参数?多个参数是否用逗号,隔开?
  4. 函数是否以括号)结尾?

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

About

Learn Python the Hard Way 练习

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages