Home  >  Article  >  Backend Development  >  What is the use of Python swapcase function?

What is the use of Python swapcase function?

青灯夜游
青灯夜游Original
2021-01-28 15:03:024970browse

In Python, the swapcase() function is used to convert uppercase and lowercase letters in a string. The syntax is "str.swapcase();"; this function can return the new characters generated after converting uppercase and lowercase letters. string.

What is the use of Python swapcase function?

#The operating environment of this tutorial: Windows 7 system, Python 3 version, Dell G3 computer.

Python swapcase()

swapcase() function is used to convert the uppercase and lowercase letters of a string, converting all uppercase letters into lowercase letters, and vice versa Of course.

Syntax

str.swapcase();

Parameters

  • NA.

Return value: Returns the new string generated after converting uppercase and lowercase letters.

Example:

#!/usr/bin/python

str1 = "this is string example....wow!!!";
print str1.swapcase();

str2 = "THIS IS STRING EXAMPLE....WOW!!!";
print str2.swapcase();

str3 = "Hello My Name Is ELON";
print str3.swapcase();

Output:

THIS IS STRING EXAMPLE....WOW!!!
this is string example....wow!!!
hELLO mY nAME iS elon

For more programming-related knowledge, please visit: Programming Video! !

The above is the detailed content of What is the use of Python swapcase function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn