#-*-coding:utf-8-*-__author__='Hunterhug'Print("Hello")#PrintHello="the "is" \ "a rather long string containing\n several lines of the text just as you would does in c.\n Note that's whitespace at the beginning of the line is\n significant."Print(Hello)#String EscapePrint("""usage:thingy \n[options]-h Display this Usage message-h hostname Hostname to connect to""")#no need to escape the linePrint(r"""usage:thingy [options]\n-h Display this Usage message-h hostname Hostname to connect to""")#Generate raw StringWord='3'+"5"word1='Str' 'ing' #two strings can beWord2='Str'. Strip () +'ing' #string expressions cannot bePrint(word*3)Print(word1)Print(WORD2)#The Python string is immutable, indexed by 0, and the last one does not takeword3='123456789'Print(word3[:])Print(word3[1:])Print(word3[:1])#123456789#23456789#1Print(Word3[:2])Print(word3[2:])# A#3456789Print(Word3[2:4])Print(Word3[2:2])# the#EmptyPrint(word3[2:100])#The default length is the character length when the lower boundary is largePrint(word3[50:200])#EmptyPrint(Word3[6:5])#Empty#CountdownPrint(word3[-1:])#9Print(Word3[:-2])#1234567Print(Word3[-2:-3])#EmptyPrint(Word3[-3:-1])# +Print(word3[-100:])#123456789 is truncated#+---+---+---+---+---+---+---+---+---+#| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |# +---+---+---+---+---+---+---+---+---+#0 1 2 3 4 5 6 7 8 9#-9-8 -7-6 -5-4 -3-2-1Print(word3[-7:-5])Print(Len (word3))#Unicode is advanced in that it provides a uniform serial number for every character appearing in a text system that is used in modern or ancient times. #previously, characters in a text system could only be in 256 possible order. Map by code page demarcation. #the text is bound to the code page of the mapped text system. This is especially problematic when software is internationalized (#usually writing i18n--' I ' + 18 characters + ' n '). #Unicode solves the challenge of setting up a separate code page for all text systems. Print('Hello\u0020world!') China="hi , hi.". Encode ('Utf-8')Print(China) Bchina=china.decode ('Utf-8')Print(Bchina)#Listlist=['spam','eggs', 100, 1234]Print(list[:])#Slice operation returns a new list with slices similar to stringlist[1]='2'Print(list[:])#variable [' spam ', ' 2 ', 1234]list[0:3]=[]Print(list)#Clear#Insertlist=['spam','eggs', 100, 1234]list[2:2]=[1,1]#InsertPrint(list)Print(list.__len__())Print(len (list)) list[3]=list#List in the listPrint(list)Print(list[3][3])Print(List[3][3][3])#Cycle#A, b = 0, 1 whileb < 10: #print (b) Print(b,end=",")#Prohibit line breakA, B = B, A +b#any nonzero integer that is true;0 is false or can be a string or a list. #It can actually be any sequence; all length nonzero is true, and the empty sequence is false. #the test in the example is a simple comparison. The standard comparison operator is the same as C: < (less than), > (greater than), = = (equals), #<= (less than or equal), >= (greater than or equal) and! = (not equal to). #Next http://docs.pythontab.com/python/python3.4/controlflow.html
Learn Python syntax from code (continuous update)