Table of Content
Print each fruit in a fruit list:
Loop through the letters in the word “banana”:
range()
FunctionPrint i as long as i is less than 6:
break
Statementcontinue
StatementContinue to the next iteration if i is 3:
This function expects 2 arguments, and gets 2 arguments:
This function expects 2 arguments, but gets only 1:
If the number of arguments is unknown, add a * before the parameter name:
You can also send arguments with the key = value syntax.
This way the order of the arguments does not matter.
If the number of keyword arguments is unknown, add a double ** before the parameter name:
Create a class named MyClass, with a property named x:
Now we can use the class named MyClass to create objects:
__init__()
FunctionThe __init __()
function is called automatically every time the class is being used to create a new object.
class的概念是屬性集合,而不是所有物
import … as …
使⽤該 package 的函式、物件要前綴 package 的名稱。
from … import … as …
將該 package 底下的函式、物件加⼊當前 namespace 中。
python
guide