Note: Two types of # or "" "" "" "or" "
#coding =utf-8 (English)
--------------------------------------------------
Variables: Declaration and definition without first declaring, assigning values
Like what:
Data_i = 1
str = ' Hello ' #字符串可用 ' or ' "
List = [1,2,[1,2], ' 1321 ']
List: An extension of an array of C languages. The element can be a normal data type or a list or other data type.
List = [1,2,[1,2], ' 1321 ']
Commonly used functions are: Append () Remove ()
--------------------------------------------------
Statements and statement blocks
No ";", for example: print ("-----------") after each statement
Use indentation to represent a block of statements, rather than a common curly brace {}
For example (statement block):
Cave_numbers = List (range (0,20))
Unvisited_caves = List (range (0,20))
Visited_caves = []
Visit_cave (0)
--------------------------------------------------
If statement
If condition:
Body
Else
Body
While statement
While condition:
Body
For statement
For I in ListName:
Body
Import usage
From random import choice
Import Random
--------------------------------------------------
Function
def functionname (Parameter1name, Parameter2name,...):
function body
return something or not
For example:
def setup_caves (cave_numbers):
"" "creat the starting list of caves" ""
Caves = []
For I in Cave_numbers:
Caves.append ([])
Return caves
--------------------------------------------------
Input and output
Print (1, end= '/t ') (or in "You can put everything)
Input (' > ') (or in ' can put everything)
Functions encountered:
Randoms = List (range) #0-19
random_i = Choice (random) #在列表中随机的选择一个元素