Take the time to brush up on the Python data structure of Peking University during a tense preparation for the Japanese language. Check the gaps.
/ divisible >>>divmod (9,5) (1,4)/ plural >>>import Cmath >>> (1+2j) * (1+3j) (-5+5j)>>> (1+4j). Imag4.0>>> (1+4j ). Real1.0
Already know the C language to use a variable must first initialize, Python's variable mechanism is reference data object, such as assignment statement ' A = 0 ' is to create a variable and then point to the value 0, the variable can point to any data object, the type of the variable will vary with the variable.
1 >>>a = 02 >>>type (a)3 <class' int '>45'0'6 >>>type (a) 7 <class'str'>
Variable Type
Because of the previous nature of the variable, the direction between the variables changes as a result of the previous variable.
1>>>alist = [A]2>>>blist = [Alist] * 33>>>blist4[[1,2,3],[1,2,3],[1,2,3]]5>>>ALIST[1] ='a'6>>>blist7[1,'a', 3],[1,'a', 3],[1,'a', 3]]
Variable Reference
A Python collection (set) is an unordered combination of elements that are not duplicated .
1>>>a = {}2>>>b = {2,3,4}3>>>a|b4{1,2,3,4}5>>>a&b6{2,3}7>>>a-b8{1}9>>>b-aTen{4) One>>>a^b A{1,4} ->>>/<, <=,>, >= subset, true subset, Hyper set, true supersetCollection Common Operations
Call function: All the things that can be called become callable. The parameters of the function are written in parentheses, and multiple parameters are separated by commas. A call to him if no parentheses are added.
1 >>>import math2 >>>a = math,sqrt (9)3 > >>a4 3.05 >>>a = math.sqrt6 >>>a (9) 7 3.0
function Call
Input from keyboard: input ()
1 / default input data format is str2 >>>name = input ('pleaseinput your name:' )3Pleaseinput your name:delete4 >>>a,b = input (). Split () 5 1 26 >>>type (a)7 <class' Str '>
input ()
Stacks, queues, and trees: specific no longer listed, see PDF.
Recursion: The problem is constantly reduced to small problems in the program, by constantly invoking themselves to achieve the purpose of solving the problem.
Three Laws of recursion:
1, recursive algorithm must have a basic end condition (the direct solution of the smallest scale problem)
2, recursive algorithm must be able to change state to basic end condition evolution (reduce problem size)
3, the recursive algorithm must call itself (to solve the same problem of reducing the size)
1 improt turtle 2 t = Turtle. Turtle () 3 w = Turtle. Screen () 4 5 def Draw (_t, Len): 6 if len > 0: 7 _t.forward (len) 8 _t.right (90 9 Draw (_t,len-5 10 11 Draw (t,100)
using recursive drawing
Above.
Python and data structures