1 #you need to import character encoding, or you will get an error if you encounter Chinese2 #Coding=utf-83 4 #1 Defining Variables5A = 106b = 27c = A +b8 Print(c)9 Ten #2 Judgment Statement OneScore = 90 A - ifScore>= 80 : - Print("very good")#there must be indentation in front the elifScore>= 60: - Print("Pass") - elifScore>=30: - Print("inferior lattice") + Else: - Print("very poor") + A #3 Cycles at forIinchRange (0,100):#Range Ranges - Print("Item {0},{1}". Format (I,"Hello Python")) - #{0} corresponds to the first parameter of format, and {1} corresponds to the second parameter of format. - - #4 Defining Functions - defSayHello (): in Print("Hello World") - toSayHello ()#executes the function. Do not indent, if there is indentation, then this line belongs to Def SayHello (): The Code + - the defMax (A, b): * ifA>B: $ returnaPanax Notoginseng Else: - returnb the + Print("The maximum value is {0}". Format (Max (12,13))) A the #5 Object-oriented + #5-1 Create a class and use the constructor method - classHello: $ #Construction Method $ def __init__(self,name): -Self._name =name; - #Defining common methods the defSay (self): - Print("Hello Python Class {0}". Format (self._name))Wuyi theH = Hello ("Heyang") - H.say () Wu - #5-2 using inheritance About classHi (Hello):#this is to inherit the Hello class $ def __init__(self,name): -Hello.__init__(Self,name) - - defSayhi (self): A Print("Hi {0}". Format (self._name)) + the -H1 = Hi ("xiaoming") $ H1.sayhi () the the the #6 Importing Files the fromMylibImportHihi - inMylib =Hihi () theMylib.hihi ()
The basics of Python