Use Python as a calculator division operation
When using/representing division operations, we generally get floating-point numbers, and if we need to get integers, we can use the operator//
Remainder calculation%
Power exponentiation
System built-in variables _
Built-in variable _, which stores the most recent results.
String
Strings can be concatenated (glued together) by the + operator and can be duplicated by *, and adjacent two string literals are automatically concatenated together.
Error usage:
x = "123"y = "456"x y #错误,SyntaxError: invalid syntaxx + y #正确x "123" #错误
Python does not have a separate character type; a character is a simple string with a length of 1. And the string has an index. When the index is negative, the calculation is started from the right
- In addition to indexes, slices are supported. The index is used to get a single character, and the slice lets you get a substring. The slice contains the starting character and does not contain the end character .
- Python gracefully handles the meaningless slicing index: an oversized index value (that is, the subscript value is greater than the actual length of the string) will be replaced by the actual length of the string, when the upper boundary is larger than the bottom edge (that is, the slice left value is greater than the right value) returns an empty string
- Python strings cannot be changed-they are immutable. Therefore, assigning a location to a string index results in an error:
Python tutorial reading Python basic and basic variables