How to change a string into uppercase?


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'

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?

Asked By: gadss



Use str.upper():

>>> s = 'sdsd'
>>> s.upper()

See String Methods.

Answered By: Dan D.

To get upper case version of a string you can use str.upper:

s = 'sdsd'
#=> 'SDSD'

On the other hand string.ascii_uppercase is a string containing all ASCII letters in upper case:

import string
Answered By: KL-7
s = 'sdsd'
print (s.upper())
upper = raw_input('type in something lowercase.')
lower = raw_input('type in the same thing caps lock.')
print upper.upper()
print lower.lower()
Answered By: H CODE

to make the string upper case — just simply type


simple and easy! you can do the same to make it lower too



Answered By: Katie T

for making uppercase from lowercase to upper
just use


where "string" is your string that you want to convert uppercase

for this question concern it will like this:


for making lowercase from uppercase string
just use


where "string" is your string that you want to convert lowercase

for this question concern it will like this:


If you want to make your whole string variable use

# sadf

Answered By: Pawanvir singh

For questions on simple string manipulation the dir built-in function comes in handy. It gives you, among others, a list of methods of the argument, e.g., dir(s) returns a list containing upper.

Answered By: bartfrenk

For converting first letter of each word into capital in a sentence

s = 'this is a sentence'


>>> 'This Is A Sentence'
Answered By: coderina

You can use capitalize() to make the 1st letter uppercase as shown below:

test = "this is a sentence."

print(test.capitalize()) # Here


This is a sentence.
Answered By: Kai – Kazuya Ito
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.