Python study notes (3) and string variables

Learning Topic: variables and strings
learning Date: 2020-02-04
Python Version: 3.7.4

Variable
to assign a value before initial use variables.
Naming of these three variables can be expressed alone or in combination with letters, numbers, underscores. But we can not start with a number. This and other language variables consistent naming convention.
Case-sensitive, A and a are not the same representation.

String
escape signals - using a backslash
such as print this out let's go inside, including 'how to print it.?
Here Insert Picture Description
Use a backslash, but the general path has backslash, the path you want to print, how to do?
Here Insert Picture Description
Here Insert Picture Description
then what should we do?
Backslash backslash escape itself
Here Insert Picture Description
, then, if the path is a lot for a backslash it. And all of a add a backslash is still very complex, how to do it?

str='C:\Program Files\Common Files\Microsoft Shared\Help';
print(str);# 这两句代码是有问题的,无法执行

Here Insert Picture Description

str='C:\\Program Files\\Common Files\\Microsoft Shared\\Help';# 每一个反斜杠后边都加一个反斜杠,对自身转义
print(str);

Here Insert Picture Description
Another simple way is to use the original string, only one letter r is added to the front of the string.

str=r'C:\Program Files\Common Files\Microsoft Shared\Help';#在最前面加入一个英文字母r
print(str);

Here Insert Picture Description
Also keep in mind here, not the last backslash in the string.
Here Insert Picture Description
Long strings
want a string across multiple lines. As follows:
the If you were Deceived by Life,
life cheats you
life cheats you
the Do not BE Dismal, do not BE Wild!
An In at The Day of grief, for the Mild BE:
. Merry Days by Will Come, Believe
Heart IS Living Tomorrow in;
Present dejected here Wallpaper iS:
the in a Moment, passes Sorrow;
that Which will bE Dear passes.
using three marks (Note: this is available in English quotes single row or double quotes).
Here Insert Picture Description
Here Insert Picture Description
Use single quotes single and two single quotes are wrong
Here Insert Picture Description

Published 75 original articles · won praise 45 · views 7323

Guess you like

Origin blog.csdn.net/hahahahhahha/article/details/104164104