Python string features and formatting methods

String: is a finite sequence of 0 or more characters

The string formatting type is as follows

Terminal or pycharm view string format type command: x.tab ()====x is the assigned variable name

x.capitalize()----capitalize the first letter

The execution result is as shown in the figure below

x.casefold()----all changed to lowercase

The execution result is as shown in the figure below

x.center()-----center filling

The execution result is as shown in the figure below

x.expandtabs()----tab function of string link

Execute as shown below

x.ljust()-----The string is filled from left to right

Execute as shown below

x.rjust()-----string fills from right to left

Execute as shown below

x.swapcase()---case swap

Execute as shown below

x.title()---Convert to title, the first letter of each word is capitalized

Execute as shown below

x.upper()-----Change all lowercase to uppercase

Execute as shown below

x.zfill()-----Specify the length of the string, and fill all the places that are not enough with 0

Execute as shown below

x.strip()-----Dead skin on both sides of the string [such as \n spaces, etc.]

Execute as shown below

x.lstrip()----remove the dead skin on the left

Execute as shown below

x.rstrip()----remove the dead skin on the right

Execute as shown below

x.format()------refer to external variables [there are 2 ways to implement this method]

Execute as shown below

Reference and assignment by parameter position

Guess you like

Origin blog.csdn.net/qq_42954795/article/details/127384215