Python swapcase() Method

Python 字符串Python Strings


Description

Python swapcase()The method is used to convert uppercase and lowercase letters in a string,That is, it converts uppercase letters to lowercase, and lowercase letters to uppercase.。

Syntax

swapcase()Method syntax:

str.swapcase();

Parameters

  • NA。

Return Value

Returns a new string with converted uppercase and lowercase letters.

Example

The following example demonstrates how to use the swapcase() function:

Example

#!/usr/bin/python str = "EXAMPLE!!!"; print ( str.swapcase() ); str = "example!!!"; print ( str.swapcase() ); str = "abCDE--example!!!"; print ( str.swapcase() );

The output of the above example is:

example!!!
EXAMPLE!!!
ABcde--example!!!

Python 字符串Python Strings

Other Extensions