SoFunction
Updated on 2024-11-07

Three methods for python string case conversion

Python provides us with three methods to facilitate case conversion of strings.

  • title()
  • lower()
  • upper()

python title() method

The title() method is used to capitalize the first letter of each word in a string and convert all other letters to lowercase. If there are no characters to be converted, the string is returned unchanged.

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6a2P5aSn5qmZ,size_20,color_FFFFFF,t_70,g_se,x_16

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6a2P5aSn5qmZ,size_20,color_FFFFFF,t_70,g_se,x_16

python lower() method

The lower() method is used to convert all uppercase characters in a string to lowercase. If there are no characters to be converted, the string is returned unchanged.

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6a2P5aSn5qmZ,size_20,color_FFFFFF,t_70,g_se,x_16

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6a2P5aSn5qmZ,size_20,color_FFFFFF,t_70,g_se,x_16

python upper() method

The upper() method is used to convert all lowercase characters in a string to uppercase. If there are no characters to be converted, the string is returned unchanged.

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6a2P5aSn5qmZ,size_20,color_FFFFFF,t_70,g_se,x_16

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6a2P5aSn5qmZ,size_20,color_FFFFFF,t_70,g_se,x_16

Note that all three methods are limited to returning the new converted string and do not change the original string.

to this article on python string case conversion of the three methods of the article is introduced to this, more related python string case conversion content please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!