How to change a string into uppercase












618















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?










share|improve this question




















  • 1





    Easy tutorial on doing this: dreamsyssoft.com/python-scripting-tutorial/strings-tutorial.php

    – Triton Man
    Jan 15 '13 at 18:05






  • 1





    Related: How to convert string to lowercase in Python? :)

    – Piotr Dobrogost
    May 5 '13 at 14:09
















618















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?










share|improve this question




















  • 1





    Easy tutorial on doing this: dreamsyssoft.com/python-scripting-tutorial/strings-tutorial.php

    – Triton Man
    Jan 15 '13 at 18:05






  • 1





    Related: How to convert string to lowercase in Python? :)

    – Piotr Dobrogost
    May 5 '13 at 14:09














618












618








618


52






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?










share|improve this question
















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?







python string uppercase






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 13 '13 at 11:01









Nope

20.2k73766




20.2k73766










asked Feb 13 '12 at 7:48









gadssgadss

7,3152978122




7,3152978122








  • 1





    Easy tutorial on doing this: dreamsyssoft.com/python-scripting-tutorial/strings-tutorial.php

    – Triton Man
    Jan 15 '13 at 18:05






  • 1





    Related: How to convert string to lowercase in Python? :)

    – Piotr Dobrogost
    May 5 '13 at 14:09














  • 1





    Easy tutorial on doing this: dreamsyssoft.com/python-scripting-tutorial/strings-tutorial.php

    – Triton Man
    Jan 15 '13 at 18:05






  • 1





    Related: How to convert string to lowercase in Python? :)

    – Piotr Dobrogost
    May 5 '13 at 14:09








1




1





Easy tutorial on doing this: dreamsyssoft.com/python-scripting-tutorial/strings-tutorial.php

– Triton Man
Jan 15 '13 at 18:05





Easy tutorial on doing this: dreamsyssoft.com/python-scripting-tutorial/strings-tutorial.php

– Triton Man
Jan 15 '13 at 18:05




1




1





Related: How to convert string to lowercase in Python? :)

– Piotr Dobrogost
May 5 '13 at 14:09





Related: How to convert string to lowercase in Python? :)

– Piotr Dobrogost
May 5 '13 at 14:09












6 Answers
6






active

oldest

votes


















1084














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


See String Methods.






share|improve this answer





















  • 132





    Also worth mentioning title(), 'abc def'.title() will give you Abc Def

    – Burhan Khalid
    Jan 14 '14 at 12:34






  • 7





    @BurhanKhalid - sir, I wish I had seen your comment before. I could have saved the trouble writing that function myself. :P

    – Harshil Pansare
    Jun 11 '15 at 6:22








  • 1





    It works for char type as well. Thank you for your helpful answer.

    – yves Baumes
    Jan 16 '16 at 14:01



















87














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'





share|improve this answer































    16














    to make the string upper case -- just simply type



    s.upper()


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



    s.lower()


    etc.






    share|improve this answer































      16














      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()





      share|improve this answer





















      • 8





        Welcome to Stack Overflow @HCode! It is customary to add some commentary to your code.

        – aliteralmind
        Jul 16 '14 at 2:57



















      5














      for making uppercase from lowercase to upper
      just use



      "string".upper()


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



      for this question concern it will like this:



      s.upper()


      for making lowercase from uppercase string
      just use



      "string".lower()


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



      for this question concern it will like this:



      s.lower()


      If you want to make your whole string variable use



      s="sadf"
      # sadf

      s=s.upper()
      # SADF





      share|improve this answer

































        1














        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.






        share|improve this answer






















          protected by Community May 6 '15 at 13:15



          Thank you for your interest in this question.
          Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



          Would you like to answer one of these unanswered questions instead?














          6 Answers
          6






          active

          oldest

          votes








          6 Answers
          6






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1084














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


          See String Methods.






          share|improve this answer





















          • 132





            Also worth mentioning title(), 'abc def'.title() will give you Abc Def

            – Burhan Khalid
            Jan 14 '14 at 12:34






          • 7





            @BurhanKhalid - sir, I wish I had seen your comment before. I could have saved the trouble writing that function myself. :P

            – Harshil Pansare
            Jun 11 '15 at 6:22








          • 1





            It works for char type as well. Thank you for your helpful answer.

            – yves Baumes
            Jan 16 '16 at 14:01
















          1084














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


          See String Methods.






          share|improve this answer





















          • 132





            Also worth mentioning title(), 'abc def'.title() will give you Abc Def

            – Burhan Khalid
            Jan 14 '14 at 12:34






          • 7





            @BurhanKhalid - sir, I wish I had seen your comment before. I could have saved the trouble writing that function myself. :P

            – Harshil Pansare
            Jun 11 '15 at 6:22








          • 1





            It works for char type as well. Thank you for your helpful answer.

            – yves Baumes
            Jan 16 '16 at 14:01














          1084












          1084








          1084







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


          See String Methods.






          share|improve this answer















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


          See String Methods.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 '14 at 16:38

























          answered Feb 13 '12 at 7:51









          Dan D.Dan D.

          54k1079101




          54k1079101








          • 132





            Also worth mentioning title(), 'abc def'.title() will give you Abc Def

            – Burhan Khalid
            Jan 14 '14 at 12:34






          • 7





            @BurhanKhalid - sir, I wish I had seen your comment before. I could have saved the trouble writing that function myself. :P

            – Harshil Pansare
            Jun 11 '15 at 6:22








          • 1





            It works for char type as well. Thank you for your helpful answer.

            – yves Baumes
            Jan 16 '16 at 14:01














          • 132





            Also worth mentioning title(), 'abc def'.title() will give you Abc Def

            – Burhan Khalid
            Jan 14 '14 at 12:34






          • 7





            @BurhanKhalid - sir, I wish I had seen your comment before. I could have saved the trouble writing that function myself. :P

            – Harshil Pansare
            Jun 11 '15 at 6:22








          • 1





            It works for char type as well. Thank you for your helpful answer.

            – yves Baumes
            Jan 16 '16 at 14:01








          132




          132





          Also worth mentioning title(), 'abc def'.title() will give you Abc Def

          – Burhan Khalid
          Jan 14 '14 at 12:34





          Also worth mentioning title(), 'abc def'.title() will give you Abc Def

          – Burhan Khalid
          Jan 14 '14 at 12:34




          7




          7





          @BurhanKhalid - sir, I wish I had seen your comment before. I could have saved the trouble writing that function myself. :P

          – Harshil Pansare
          Jun 11 '15 at 6:22







          @BurhanKhalid - sir, I wish I had seen your comment before. I could have saved the trouble writing that function myself. :P

          – Harshil Pansare
          Jun 11 '15 at 6:22






          1




          1





          It works for char type as well. Thank you for your helpful answer.

          – yves Baumes
          Jan 16 '16 at 14:01





          It works for char type as well. Thank you for your helpful answer.

          – yves Baumes
          Jan 16 '16 at 14:01













          87














          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'





          share|improve this answer




























            87














            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'





            share|improve this answer


























              87












              87








              87







              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'





              share|improve this answer













              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'






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Feb 13 '12 at 7:56









              KL-7KL-7

              32.4k87571




              32.4k87571























                  16














                  to make the string upper case -- just simply type



                  s.upper()


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



                  s.lower()


                  etc.






                  share|improve this answer




























                    16














                    to make the string upper case -- just simply type



                    s.upper()


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



                    s.lower()


                    etc.






                    share|improve this answer


























                      16












                      16








                      16







                      to make the string upper case -- just simply type



                      s.upper()


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



                      s.lower()


                      etc.






                      share|improve this answer













                      to make the string upper case -- just simply type



                      s.upper()


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



                      s.lower()


                      etc.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jun 27 '16 at 15:50









                      Katie TKatie T

                      19114




                      19114























                          16














                          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()





                          share|improve this answer





















                          • 8





                            Welcome to Stack Overflow @HCode! It is customary to add some commentary to your code.

                            – aliteralmind
                            Jul 16 '14 at 2:57
















                          16














                          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()





                          share|improve this answer





















                          • 8





                            Welcome to Stack Overflow @HCode! It is customary to add some commentary to your code.

                            – aliteralmind
                            Jul 16 '14 at 2:57














                          16












                          16








                          16







                          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()





                          share|improve this answer















                          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()






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Oct 16 '17 at 11:11









                          Community

                          11




                          11










                          answered Jul 16 '14 at 0:49









                          H CODEH CODE

                          17912




                          17912








                          • 8





                            Welcome to Stack Overflow @HCode! It is customary to add some commentary to your code.

                            – aliteralmind
                            Jul 16 '14 at 2:57














                          • 8





                            Welcome to Stack Overflow @HCode! It is customary to add some commentary to your code.

                            – aliteralmind
                            Jul 16 '14 at 2:57








                          8




                          8





                          Welcome to Stack Overflow @HCode! It is customary to add some commentary to your code.

                          – aliteralmind
                          Jul 16 '14 at 2:57





                          Welcome to Stack Overflow @HCode! It is customary to add some commentary to your code.

                          – aliteralmind
                          Jul 16 '14 at 2:57











                          5














                          for making uppercase from lowercase to upper
                          just use



                          "string".upper()


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



                          for this question concern it will like this:



                          s.upper()


                          for making lowercase from uppercase string
                          just use



                          "string".lower()


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



                          for this question concern it will like this:



                          s.lower()


                          If you want to make your whole string variable use



                          s="sadf"
                          # sadf

                          s=s.upper()
                          # SADF





                          share|improve this answer






























                            5














                            for making uppercase from lowercase to upper
                            just use



                            "string".upper()


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



                            for this question concern it will like this:



                            s.upper()


                            for making lowercase from uppercase string
                            just use



                            "string".lower()


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



                            for this question concern it will like this:



                            s.lower()


                            If you want to make your whole string variable use



                            s="sadf"
                            # sadf

                            s=s.upper()
                            # SADF





                            share|improve this answer




























                              5












                              5








                              5







                              for making uppercase from lowercase to upper
                              just use



                              "string".upper()


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



                              for this question concern it will like this:



                              s.upper()


                              for making lowercase from uppercase string
                              just use



                              "string".lower()


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



                              for this question concern it will like this:



                              s.lower()


                              If you want to make your whole string variable use



                              s="sadf"
                              # sadf

                              s=s.upper()
                              # SADF





                              share|improve this answer















                              for making uppercase from lowercase to upper
                              just use



                              "string".upper()


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



                              for this question concern it will like this:



                              s.upper()


                              for making lowercase from uppercase string
                              just use



                              "string".lower()


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



                              for this question concern it will like this:



                              s.lower()


                              If you want to make your whole string variable use



                              s="sadf"
                              # sadf

                              s=s.upper()
                              # SADF






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited May 1 '18 at 5:56









                              Keyur Potdar

                              5,64451631




                              5,64451631










                              answered Sep 1 '16 at 16:36









                              Pawanvir singhPawanvir singh

                              178211




                              178211























                                  1














                                  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.






                                  share|improve this answer




























                                    1














                                    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.






                                    share|improve this answer


























                                      1












                                      1








                                      1







                                      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.






                                      share|improve this answer













                                      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.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Oct 15 '18 at 22:28









                                      bartfrenkbartfrenk

                                      3824




                                      3824

















                                          protected by Community May 6 '15 at 13:15



                                          Thank you for your interest in this question.
                                          Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                          Would you like to answer one of these unanswered questions instead?



                                          Popular posts from this blog

                                          404 Error Contact Form 7 ajax form submitting

                                          How to know if a Active Directory user can login interactively

                                          TypeError: fit_transform() missing 1 required positional argument: 'X'