(1) Defining variables
1 a =2 b = 23 c = a + b
(2) Judgment statement
1Score = 902 3 ifScore >= 80 :4 Print("Excellent")5 elifScore >= 70 :6 Print("Medium")7 elifScore >= 60 :8 Print("Pass")9 Else:Ten Print("inferior lattice")
(3) Cycle
1 forIinchRange (0,5,2):2 Print(i)3 Print("================")4 forIinchRange (0,5):5 Print(i)6 Print("================")
Print ("Item {0} {1}". Format ("eee"))
For I in Range (0,5):
Print (i)
Else
Print ("Loop End")
(4) function
1 defSayHello ():2 Print("Hello World")3 4 SayHello ()5 6 defMymax (x, y):7 ifX >y:8 PrintX"is Max"9 Else:Ten PrintY"is Max" OneMymax (10,9) A - defmymaxval (x, y): - ifX >y: the returnx - returny - - Print(Mymaxval (10,8))
(5) Object
1 classHello:2 def __init__(self, name):3Self.name =name4 Print("Hello Constructor")5 def __del__(self):6 Print("Hello destructor")7 8 defSayHello (self):9 Print("Hello {0}". Format (self.name))Ten One classHi (Hello): A def __int__(self,name): -Hello.__init__(Self,name) -Self.name =name the Print("Hi constructor Function") - - defSayhi (self): - Print("Hi {0}". Format (self.name)) + - #Hello Object +H = Hello ("Zhangsan") A H.sayhello () at - #Hi Object -hi = Hi ("Lisi") - Hi.sayhi () -Hi.sayhello ()
2. Basic syntax for Python language