I have problem in changing a string into uppercase with Python. In my research, I got string.ascii_uppercase
but it doesn't work.
The following code:
>>s = 'sdsd' >>s.ascii_uppercase
Gives this error message:
Traceback (most recent call last): File "<console>", line 1, in <module> AttributeError: 'str' object has no attribute 'ascii_uppercase'
My question is: how can I convert a string into uppercase in Python?
Java String toUpperCase() MethodThe toUpperCase() method converts a string to upper case letters. Note: The toLowerCase() method converts a string to lower case letters.
Program to convert the uppercase string into lowercase using the strlwr() function. Strlwr() function: The strlwr() function is a predefined function of the string library used to convert the uppercase string into the lowercase by passing the given string as an argument to return the lowercase string.
Use str.upper()
:
>>> s = 'sdsd' >>> s.upper() 'SDSD'
See String Methods.
To get upper case version of a string you can use str.upper
:
s = 'sdsd' s.upper() #=> 'SDSD'
On the other hand string.ascii_uppercase
is a string containing all ASCII letters in upper case:
import string string.ascii_uppercase #=> 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With