Self-taught python note string assignment with little turtle is updating...

After reading these notes, you can get started with Python.
Watch the video of Little Turtle on Station B, and organize your notes by the way.

1. How to define a string that spans multiple lines

Method one:
str1 = ''' 待我长发及腰,将军归来可好? 此身君子意逍遥,怎料山河萧萧。 天光乍破遇,暮雪白头老。 寒剑默听奔雷,长枪独守空壕。 醉卧沙场君莫笑,一夜吹彻画角。 江南晚来客,红绳结发梢。 '''
Method two: str2 = ' 待卿长发及腰,我必凯旋回朝。 \ 昔日纵马任逍遥,俱是少年英豪。 \ 东都霞色好,西湖烟波渺。 \ 执枪血战八方,誓守山河多娇。 \ 应有得胜归来日,与卿共度良宵。 \ 盼携手终老,愿与子同袍。 '
Method three:str3 = (' 待卿长发及腰,我必凯旋回朝。 ' '昔日纵马任逍遥,俱是少年英豪。 ' '东都霞色好,西湖烟波渺。 ' '执枪血战八方,誓守山河多娇。 ' '应有得胜归来日,与卿共度良宵。 ' '盼携手终老,愿与子同袍。 ')

2. file1 = open('C:\windows\temp\readme.txt','r') means to open the text file "C: \windows\temp\readme.txt'" in read-only mode, but in fact this The statement will report an error, do you know why? How would you modify it?

      The error is reported because in the string, we agree that "t" and "r" represent "horizontal tab (TAB)" and "carriage return" respectively. Therefore, the file will not be opened according to the path we planned.
      You need to use the primitive string operator (R or r):file1 = open(r'C:\windows\temp\readme.txt', 'r')

3. There is a string: str1 ='<href=“http://www.fishc.com/dvd” target="_blank">', how to extract the substring:'www.fishc.com'
str1[14:27]
4. What does it mean to use negative numbers as index values ​​for sharding operations?

It can be clearly seen from the following that the negative number of slices indicates the number of reversed
Insert picture description here

5. The following output

Insert picture description here
Represents output every two characters from the beginning to the end of the string

Guess you like

Origin blog.csdn.net/A_Tu_daddy/article/details/105122125