25 C
Jaipur
Sunday, November 29, 2020

Python uppercase string – Linux Hint

Must read

Dyson Black Friday deals: save big on cordless and upright vacuum cleaners

Black Friday has shut its sales shop for another year – but the offers aren't over yet, as Cyber Monday deals are kicking off...

A New Tomb Raider Mobile Game Is Coming in 2021

After releasing the last title under the Lara Croft: Tomb Raider series back in 2018, Square Enix, the publisher of the Tomb Raider titles...

This Computer Chip Simulates the Future Faster Than Physics

As we are moving towards the future, computer companies are making their chipsets more and more powerful. For instance, Apple’s latest M1 chip has...

20 hot Amazon Black Friday deals you can still get ahead of Cyber Monday 2020

With Cyber Monday approaching in the UK, Amazon's best Black Friday deals are mostly still in stock going into Sunday. While we've seen sellouts...

The upper() function translates all the lowercase characters in a string into uppercase and returns the string. The upper() function is an integral function in Python. In certain cases, the upper() function is very useful. For example, if we are developing a university management system and want to convert the name of all the students into uppercase letters, in this case, we will definitely use the upper() function. This article explains the use of the upper() function with the help of simple examples.

The syntax of upper() function

The syntax of the upper() function is:

str.upper()

While using the upper() function, we just have to write the name of our string and call the upper() function. Let’s see the examples of upper() function.

Examples

Let’s declare a lowercase character string and convert it to the uppercase characters.

#declaring a lowercase string
name = “kamran sattar awaisi”
#printing the original string
print(“This is the original string:”)
print(name)

#converting the string into uppercase
print(“This is the converted string:”)
print(name.upper())

Output


Now let’s declare a string that has few lowercase letters and few uppercase letters. The upper() function will convert the whole string into uppercase letters.

#declaring a lowercase string
name = “LinuxHint is WEb BasEd Learning PoRtal”
#printing the original string
print(“This is the original string:”)

print(name)

#converting the string into uppercase
print(“This is the converted string:”)
print(name.upper())

Output


There are many applications of the upper() function. For example, Python is a case sensitive language. If we want to compare the two string, we can convert them into uppercase, and then we can compare them.

#declaring first string
name_str1= “kamran sattar awaisi”
#declaring the second string
name_str2=“KAMrAn saTTAR aWaiSI”
#converting the strings into uppercase and comparing them
if name_str1.upper()==name_str2.upper():
    print(“Both the strings are same”)
else:
    print(“The strings are not same”)

Output

Conclusion

The upper() function is used to convert the string uppercase characters. This article explains the use of the upper() function with the help of simple examples.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

Dyson Black Friday deals: save big on cordless and upright vacuum cleaners

Black Friday has shut its sales shop for another year – but the offers aren't over yet, as Cyber Monday deals are kicking off...

A New Tomb Raider Mobile Game Is Coming in 2021

After releasing the last title under the Lara Croft: Tomb Raider series back in 2018, Square Enix, the publisher of the Tomb Raider titles...

This Computer Chip Simulates the Future Faster Than Physics

As we are moving towards the future, computer companies are making their chipsets more and more powerful. For instance, Apple’s latest M1 chip has...

20 hot Amazon Black Friday deals you can still get ahead of Cyber Monday 2020

With Cyber Monday approaching in the UK, Amazon's best Black Friday deals are mostly still in stock going into Sunday. While we've seen sellouts...

This VR App Can Take You Places Using Google’s Street View

This year, as we all know, has been one of the most disastrous years in the history of our world. Apart from the ongoing...