1. Python code delays waiting:
Import the time module, the parameter unit in sleep is seconds
import time
print(“hello”)
time.sleep(1)
print(“world”)
Two, printh wrap:
Default print() wraps automatically
print("hello",end='')
No line break after adding end
Three, create a fixed size one-dimensional array, two-dimensional array
1. Create a one-dimensional array: create a one-dimensional array with
a length of 5 and a value of "
list=['']*5
2. Create a two-dimensional array.
You can use numpy to
create a 5*5 matrix
import numpy as np
np.zeros((5,5))
Four, report an error
1. Python error: UnboundLocalError: local variable x referenced before assignment is
generally a problem when referencing variables. You can pass global variables as parameters to the function, or you can add global declarations before using variables.
#作为参数传入
def f(n):
f+=1
#声明global
def f:
global n
n+=1
2. Python error: ValueError:'c' argument has 5 elements, which is inconsistent with'x' and'y' with size 4.
When it appears in the drawing, it is usually caused by the color sequence inconsistent with the number of nodes
3. Python error: AttributeError: module'tkinter' has no attribute'filedialog'
appears in the file dialog to call, from tkinter import filedialog
just call the filedialog module