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

What is the use of Python swapcase function?

青灯夜游
Release: 2022-12-30 11:12:55
Original
5096 people have browsed it

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();
Copy after login

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();
Copy after login

Output:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template