Python Learning notes (i)

Source: Internet
Author: User

#Encoding:utf-8#you need to specify the encoding#Introducing SYSImportSYS#introduction of files in the same directoryImportfunction1#output a line of welcome informationPrint "Hello World"##basic Data type:#int#float#BOOL#Long###the array in Python:#list: [1,2,3]--can change the value#Tuple: (--)--Non-changing values##access rules:#List[start:end:step] default is 0#Find objects:#in or not in; Returns a Boolean value that determines whether the#a=[1,2,3]A1=[4,5,6]b= (A)PrintA[0:2]PrintbPrint1inchb#string#str= ' Hello World ' direct useStr='This is a string'Print '\ ' this\ ' in the str:',' This' inchStrPrintStr#% number operatorPrint "Int%d, Float%d, String '%s '"% (5, 2.3,'Hello')#Dictionary data Typesbox={'a':'Apach','b':['str1','str2'],'C': 19284};Print 'box[\ ' a\ ']=', box['a']Print 'box[\ ' b\ ']=', box['b']#Branching StructureNumber=90ifnumber>=85 andnumber<100 :    Print 'A'elifNumber>60 andNumber <85 :    Print 'B'Else :    Print 'C'#Loop StructurePrint 'Loop structure:'I=0 while(i<10) :    Print 'i=', I i=i+1 forDinchStr:sys.stdout.write (d)PrintFunction1.f1 (a)
#If you want to use code that is not in the current module, you need to use import, as we all know. #If you want to use the module (PY file) and the current module in the same directory, just import the corresponding file name, such as the use of b.py in a.py:#Import B#But what if you want to import a file of a different directory (for example, b.py)? #you first need to use the Sys.path.append method to add the directory where b.py resides in the search directory. Then import them, for example#Import SYS#sys.path.append (' c:\xxxx\b.py ') # This example is for Windows usersdefF1 (x):PrintxdefF2 (x):PrintX+1

Python Learning notes (i)

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.