This chapter will show you how to use strings to Ho Shihua other values (such as printing a specially formatted string) and simply understand what you can do with the segmentation, joins, and searches of strings.
3.1 Basic string manipulation
All standard sequence Operations (index, Shard, multiply, Judge membership, length, minimum, and maximum) also apply to strings, keeping in mind that strings are immutable .
3.2 String Formatting: Lite version
String formatting is applied to the string formatting operator, which is the percent% to implement
The left side of the% prevents a string (formatted string), while the right side places the value you want to format. You can use a value, such as a string or a number, or you can use a tuple of multiple values or a dictionary that will be discussed in the next chapter, which is discussed in the next section. In general, tuples are used:
>>>format = ' Hello,%s. '%s enough for ya> '
>>>values = (' World ', ' hot ')
>>>hello.world.hot enough for ya?
If you want to format real numbers (floating-point numbers), you can use the F-specifier type, and colleagues provide the required precision: a period plus the number of decimal digits you want to keep. Because the formatting specifier always ends with a character that represents a type, the precision should precede the type character:
>>>format = ' pi with three decimals:%.3f '
>>>from Math Import Pi
>>>print (from%pi)
>>>pi with three decimals:3.142
3.3 String Formatting: Full version
The right operand of the format operator can be anything, and if it is a tuple or a mapping type (such as a dictionary), the string formatting will be different. We haven't covered the mappings yet, so we'll look at the tuples again.
If the right operand is a tuple, then each of these elements is individually formatted, and each value requires a corresponding conversion specifier
Basic Python Tutorial-chapter III-Using Strings