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.?
Use a backslash, but the general path has backslash, the path you want to print, how to do?
then what should we do?
Backslash backslash escape itself
, 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);# 这两句代码是有问题的,无法执行
str='C:\\Program Files\\Common Files\\Microsoft Shared\\Help';# 每一个反斜杠后边都加一个反斜杠,对自身转义
print(str);
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);
Also keep in mind here, not the last backslash in the string.
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).
Use single quotes single and two single quotes are wrong