0
How to swap a string by taking characters in uppercase and coverting in lowr one or vice versa
Phython
5 Réponses
+ 3
The easiest way would be to use str.swapcase().
A manual solution could look something like this:
s = 'Hello World'
print(''.join([c.lower() if c == c.upper() else c.upper() for c in s])) # hELLO wORLD
0
Robert Carsten but can't we take two string as uppercase and lowercase and swap them by using swap function
0
Robert Carsten sorts of but I understand thanks
- 1
If you mean just making the letters uppercase or lowercase you could use the appropriate string method
"String".upper()
"String".lower()
- 1
Perhaps I'm misunderstanding so tell me if this is the output you are looking for
a = "STRING"
b = "string"
a,b = b,a
print(a,b)
>> string STRING