Number
There are 4 types of numbers in Python--integers, long integers, floating-point numbers and complex numbers
String
- Use single quotation marks (')
- Use double quotation marks (")
Identical to single quote use
- Use three quotation marks ("' or" ")
Indicates a multi-line string. Single and double quotes are freely available in three quotation marks
Print ("' This is multi-linestring the ' first line, this issecond line " Double quotation marks can be used " ' single quotation mark can also be used ' There is also a blank line below ")
Results:
In a string, a single backslash at the end of the line \ Indicates that the string continues on the next line instead of starting a new row.
"This is the first sentence.\
This is the second sentence. "
Equivalent to "This is the first sentence." This is the second sentence. "
Indicates that a specially processed string, such as an escape character, is not required. specified by prefixing the string with R or R. For example R "string\n". Output: string\n
Handles text written in languages that contain non-English language. By prefixing the string with U. For example, U "This is a Unicode string".
- The string is immutable
- Concatenate strings by literal meaning
If you put two strings next to each other literally, they will be automatically connected by Python. For example ' what\ ' ' Your name? ' will be automatically converted to "What's your name?".
Variable
Python simply assigns a value to a variable when it is used, and does not need to declare or define the data type.
Indent in
whitespace (blank cells and tabs) at the beginning of a logical line is used to determine the indentation level of logical lines, which is used to determine the grouping of statements.
Statements at the same level must have the same indentation, which is called a block.
Excerpt from Python's Concise tutorial Chinese
Basic Python Concepts