Write a program to display only lower case characters of a string convert to uppercase in python

Convert all lowercase letters to uppercase letters in python; Through this tutorial, you will learn how to convert all lowercase letters to uppercase letters or characters or string in python.

Python has many built-in functions/methods for manipulation with strings, which you can check here (python string methods).

1: Convert lowercase to uppercase in python with using the function

You can use the python string method/function that name upper(), This method converts all letters or characters of string lowercase to uppercase.

The syntax of upper() method is:

string.upper()

String upper() Parameters()

The upper() method doesn’t take any parameters.

Return value from String upper()

The upper() method returns the uppercased string from the given string. It converts all lowecase characters to uppercase.

If no lowercase characters exist, it returns the original string.

Example 1: write a program to convert all lowercase to uppercase characters in python

# example string string = "This is first example of convert string lowercase to uppercase" print(string.upper()) #Output #THIS IS FIRST EXAMPLE OF CONVERT STRING LOWERCASE TO UPPERCASE

2: How to convert lowercase to uppercase in python without using string function

As you have seen in the example given above, we have done how to convert all the letters of string from lowercase to uppercase by using the upper() method of Python.

To write a program in Python that will convert all the letters of the string from lowercase to uppercase without using any Python function:

# convert lowercase to uppercase in python without using function st = 'how to convert lowercase to uppercase in python without using string function' out = '' for n in st: if n not in 'abcdefghijklmnopqrstuvwqxyz': out = out + n else: k = ord(n) l = k - 32 out = out + chr(l) print('------->', out)

The output of above python program is:

HOW TO CONVERT LOWERCASE TO UPPERCASE IN PYTHON WITHOUT USING STRING FUNCTION

There are several built-in methods that allow us to easily make modifications to strings in Python. In this tutorial we will cover the .upper(), .lower(), .count(), .find(), .replace() and str() methods.

But first, let’s take a look at the len() method. While it’s not limited to strings, now is a good time to make the introduction. We use the built-in Python method, len(), to get the length of any sequence, ordered or unordered: strings, lists, tuples, and dictionaries. For example:

>>> s = “This string contains forty-two characters.>>> len(s) 42

.upper() & .lower()

The .upper() and .lower() string methods are self-explanatory. Performing the .upper() method on a string converts all of the characters to uppercase, whereas the lower() method converts all of the characters to lowercase.

>>> s = “Whereof one cannot speak, thereof one must be silent.>>> s 'Whereof one cannot speak, thereof one must be silent.' >>> s.upper() 'WHEREOF ONE CANNOT SPEAK, THEREOF ONE MUST BE SILENT.' >>> s.lower() 'whereof one cannot speak, thereof one must be silent.'

.count()

The .count() method adds up the number of times a character or sequence of characters appears in a string. For example:

>>> s = "That that is is that that is not is not is that it it is" >>> s.count("t") 13

Why didn’t it count all of the t‘s? Because ‘T’ is a different character from ‘t’. So, if we want to count all of the t‘s.

>>> s = s.lower() >>> s.count("t") 14

We can also count entire words, which, as we know, are sequences of characters:

s = "James while John had had had had had had had had had had had a better effect on the teacher" >>> s.count("had") 11

.find()

We search for a specific character or characters in a string with the .find() method.

s = "On the other hand, you have different fingers." >>> s. find("hand") 13

The results tell us that “hand” begins at the 13th position in the sequence.

But if we want to find the second “o” we need to specify a range.

This begins searching at the 8th element and finds “o” at 20. You can also specificy an end to the range, and, like slicing, we can do so backwards:

>>> s.find("e", 20, -5) 26

.replace()

Let’s say we want to increase the value of a statement. We do so with the .replace() method. For example:

>>> s = "I intend to live forever, or die trying." >>> s.replace("to", "three") 'I intend three live forever, or die trying.' >>> s.replace("fore", "five") 'I intend to live fivever, or die trying.'

String Conversion

How does one become one with everything? With the str() method.

>>> one = str(1) >>> one '1'

Now that you are enlightened, you can stop learning Python and live in the moment. OR: You can learn about lists in our next chapter.