{"id":5090,"date":"2023-10-26T15:29:26","date_gmt":"2023-10-26T09:59:26","guid":{"rendered":"https:\/\/python-programs.com\/?p=5090"},"modified":"2023-11-10T12:01:26","modified_gmt":"2023-11-10T06:31:26","slug":"python-string-upper-method","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-string-upper-method\/","title":{"rendered":"Python: String upper() Method"},"content":{"rendered":"
A Python string is a collection of characters surrounded by single, double, or triple quotes. The computer does not understand the characters; instead, it stores the manipulated character as a combination of 0\u2019s and 1\u2019s internally.<\/p>\n
In this article we are going to discuss the use of upper() function.<\/p>\n
The string upper() method returns a string that has all lowercase characters converted to uppercase characters.<\/p>\n
Syntax:<\/strong><\/p>\n Parameters:<\/strong><\/p>\n Return:<\/strong><\/p>\n We can convert it using built in function upper().<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explanation:<\/strong><\/p>\n It returned a copy of the given string, and all lowercase characters were converted to uppercase characters in the returned copy. The uppercase copy of the string was then assigned to the original string.<\/p>\n As the above method we can convert it to uppercase using upper() function.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We can convert the given two strings to upper() function and we can compare them using “=” operator.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We can convert it using built in function upper().<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n A Python string is a collection of characters surrounded by single, double, or triple quotes. The computer does not understand the characters; instead, it stores the manipulated character as a combination of 0\u2019s and 1\u2019s internally. In this article we are going to discuss the use of upper() function. String upper() Method in Python Upper() …<\/p>\ngiven_string.upper()<\/pre>\n
The upper() method does not accept any parameters.<\/pre>\n
The upper() method returns the uppercased version of the given string. All lowercase characters are converted to uppercase.\r\n\r\nIf no lowercase characters are found, the original string is returned.<\/pre>\n
2)Converting a string to uppercase<\/h3>\n
# given string\r\nstring = \"btech geeks\"\r\n# converting string to upper\r\nstring = string.upper()\r\n# print the string\r\nprint(string)\r\n<\/pre>\n
BTECH GEEKS<\/pre>\n
3)Converting the string which has numbers and letters to uppercase<\/h3>\n
# given string\r\nstring = \"btech 2021 geeks\"\r\n# converting string to upper\r\nstring = string.upper()\r\n# print the string\r\nprint(string)\r\n<\/pre>\n
BTECH 2021 GEEKS<\/pre>\n
4)Convert two strings to uppercase and compare them<\/h3>\n
# given string\r\nstring1 = \"BTechGeeks\"\r\nstring2 = \"btechgeeks\"\r\n# converting both strings to uppercase using upper() function\r\nstring1 = string1.lower()\r\nstring2 = string2.lower()\r\n# compare the two strings\r\nif(string1 == string2):\r\n print(\"Both strings are equal\")\r\nelse:\r\n print(\"Both strings are not equal\")\r\n<\/pre>\n
Both strings are equal<\/pre>\n
5)Convert character to uppercase<\/h3>\n
# given character\r\ncharacter = 'b'\r\n# convert to uppercase using upper() function\r\ncharacter = character.upper()\r\n# print the character\r\nprint(character)\r\n<\/pre>\n
B<\/pre>\n
\n