#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)