A byte of Python
To know the basic of Python
listing 5.1 while loop
1 | number = 23 |
listing 5.2 for loop
1 | for i in range(1,5): |
listing break statement
1 | while(True): |
listing 5.4 continue
1 | while(True): |
listing 5.5 python
1 | def sayHello(): |
listing 7.2 using function x para
1 | def printMax(a,b): |
listing 7.3 using local variable
1 | def func(x): |
listing 7.4 using global statement
1 | def globalF(): |
listing 7.5 using default paras
1 | def say(message,times = 1): |
listing 7.6 use key para
1 | def func(a, b = 5, c = 10): |
listing 7.7 use return
1 | def maximum(x,y): |
listing 7.8
1 | def someFuntion(): |
listing 7.9 docStrings
1 | def printMax(x,y): |
listing 8.1 using System module
1 | import sys |
listing 8.2 using module name
1 | if(__name__=='__main__'): |
listing 8.3 how to use module
1 | #mymodule.py |
listing 8.4 dir()
1 | $python |
listing 8.5 list()
1 | # this is my shopping list |
listing 8.6 tuple
1 | zoo = ("wolf", "elephant", "penguin") |
listing 8.7 using tuple output
1 | age = 22 |
listing 8.8 using dict
1 | # using _dict.py |
using seq
1 | #Filename: seq.py |
listing 9.6 using object and reference
1 | # reference |
实际上就是一个是引用类型,一个是新对象?如果想要
listing 9.7 str methods
1 | # str_methods.py |
listing 11.1 use class
1 | #simple class .py |
listing 11.2 use object method
1 | #method.py |
listing 11.3 using init
1 | class Person: |
listing 11.4 use class and object var
1 | #objvar.py |
继承
listing 11.1 use inherit
1 | #inherit.py |
文件IO
listing 12.1 use_file.py
1 | #using_file.py |
数据持久化 cPickle
listing Save and load
1 | #Filename:pickling.py |
list 13.1 try catch
1 | try: |
listing 13.2
1 | #filename: raising.py |
listing 13.3 use finally
1 | import time |
listing 14.1 use sys.argv
1 | # filename: cat.py |
listing extra uss sys.argv in C#
1 | namespace hohoho |
listing 15.1 use comprehension
1 | # filename: list_comprehension.py |
listing 15.2 use lambda
1 | # filename: use lambda |
只能使用表达式在lambda中