First, the data type in Python mainly has the following five kinds of
(1), Integer
(2), floating point
(3), string: Any text enclosed in "or"
(4), Boolean: Only True and False two kinds of values (note that two are uppercase), Boolean values can be used and, or and not operations, Python, 0 空字符串‘‘ and as None false, and other numeric and non-empty strings are considered True;
(5), null: A special value in Python, represented by none, but none cannot be understood as 0, because 0 is meaningful, and none is a special null value;
How to define a string in Python we already know to use "and" to express, but sometimes it involves the escape character, so here is a detailed summary, haha.
(1), when the string itself with the single quotation mark "", we choose to use double quotation marks "" to represent the string, conversely, when the string itself with double quotation marks "", we use single quotation marks "" to represent.
(2), of course, we can also choose another method to replace the above method-the string itself with the "and" before the backslash \ to solve;
(3), if a string contains a lot of characters that need to be escaped, it is cumbersome to escape each character, in order to avoid this situation, we can prefix the string to r indicate that this is a raw string, the inside of the characters do not need to escape. However, the r‘...‘ notation cannot represent multiple lines of string, nor can it represent a ‘ string containing and, if you " want to represent a multiline string, you could add it in front of a multiline string, and you can also ‘‘‘...‘‘‘ r turn the multiline string into a Raw string:
three, the string also has a coding problem.
Because a computer can only handle numbers, if you are working with text, you must convert the text to a number before processing it. In order to unify all text encoding, Unicode came into being. Unicode unifies all languages into a set of encodings, so there is no more garbled problem.
Python later added support for Unicode, with a Unicode-represented string expressed in U ' ... ', for example:
Print U ' Chinese '
Note: without u, Chinese will not display properly.
Escape:
U ' chinese \ n \ japanese \ Korean '
MultiRow
U ' ' first line second line '
raw+ Multiple lines:
ur ' python's Unicode string supports "Chinese", "Japanese", "Korean" and many other languages "
If the Chinese string encounters unicodedecodeerror in a Python environment, this is because there is a problem with the format saved by the. py file. You can add comments on the first line
#-*-Coding:utf-8-*-
The purpose is to tell the Python interpreter to read the source code with UTF-8 encoding. Then save with notepad++ as ... and select UTF-8 format to save.
Python variables and data types