First, the use of escape characters
In practical applications, we may want to refer to someone else's words or use abbreviations, this time, in the print () function, in order to print the quotation marks as characters, you have to use the escape character "\".
For example, when we print the He says, "Forget the memories,continue to is Life,miss,just pass by." , you can do this
>>>print ("He says, \" Forget the memories,continue to be Life,miss,just pass by.\ ")
#反斜杠 \ In front of quotation marks, double quotation marks as one character
In addition, you can do this
>>>print ('He says, ' Forget the memories,continue to being Life,miss,just pass by. ' ) ')
#当要打印的语句里面有引号时, you can use a different quotation mark as an indicator, which can do the same thing.
>>>print ('Wise men learn by other men\ 's mistakes,fools by their own') #通过在men ' s ' in front plus backslashes \, Makes Python think of a character so that it can perfectly solve the wise men learnby the other men'smistakes,fools by their own
Two, concatenate multiple strings
Concatenate multiple strings Yes, use the "+" sign. However, if you want to output a result with an interval, you need to increase the space string
>>>print ('Alex''ammy') Alex Ammy
Of course, if you use the print () function, you can separate the strings by using commas directly:
>>>print ('Alex','ammy','Mike ' ) Alex Ammy Mike
In addition, if we want to customize the output format, you can use the format specifier "%", and you can add a value that represents the length after "%", for example
>>>print ("%s%s%10s" % ('John','Mike', ' Mans ' )) John Mike man
#10表示一个长度为10的字符串, the third character man takes 3 bits, then it fills 7 spaces
>>>print ("%f"% (43.5-36.1))
7.400000
>>>print ("%.2f"% (43.5-36.1))
7.40
If you want to print "%", you can add a "%" before "%".
DAYS1 Summary of basic learning in Python