The basics of Python

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.