
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to get max alphabetical character from the string in Python?
A string is a group of characters that may be used to represent a single word or an entire phrase. Strings are simple to use in Python since they do not require explicit declaration and may be defined with or without a specifier.
Python provides a variety of built in functions and methods for manipulating and accessing strings in the class named string.
In this article, we are going to find out how to get the max alphabetical character from the given string in python.
The max() function
The most used approach for this problem is the max() function from the inbuilt python library. Everyone would assume that this function is used only for finding out the maximum number or float from a given list but, it can also be used to find out the largest or max alphabetical character from a given string.
It takes a string as input and returns the largest letter from it.
But there is one problem with this approach, this compares by using ASCII values, so there may be some errors when the string is of different casing because the lower case letters have higher ASCII values.
To overcome this, we should convert the string into the same case either Upper case or lower case before computing max.
Example 1
In the below given example, we are taking a string that is entirely in the upper case and we are performing the max operation on that string and we are getting the maximum alphabetical character.
str1 = "WELCOME TO TUTORIALSPOINT" print("The maximum alphabetical character from the string is") print(max(str1))
Output
The output of the above given example is,
The maximum alphabetical character from the string is W
Example 2
In the example given below, we are taking the string input with only one capital letter and the rest of them are lower case and performing the max operation. There would be a discrepancy in the final answer because of the ASCII values.
str1 = "Welcome to tutorialspoint" print("The maximum alphabetical character from the string is") print(max(str1))
Output
The output of the above program is,
The maximum alphabetical character from the string is u
Example 3
In the example given below, we are taking the same input as before but we are rectifying our mistake by changing the case of the string before using the max operation.
str1 = "Welcome to tutorialspoint" str2 = str1.upper() print("The maximum alphabetical character from the string is") print(max(str2))
Output
The output of the above program is,
The maximum alphabetical character from the string is W
Example 4
In the example given below, we are using special characters and integers in the string and we are using the max operation on this string.
str1 = "Welcome to tutorialspoint@123" str2 = str1.upper() print("The maximum alphabetical character from the string is") print(max(str2))
Output
The output of the above string is,
The maximum alphabetical character from the string is W
- Related Articles
- How to get min alphabetical character from the string in Python?
- C# program to get max occurred character in a String
- Python Program to Get a Character From the Given String
- Removing n characters from a string in alphabetical order in JavaScript
- Get the max n values from an array in JavaScript
- Python program for removing n-th character from a string?
- Java Program to Get a Character From the Given String
- Program to find how max score we can get by removing 10 or 01 from binary string in Python
- How to delete a character from a string using python?
- C# program to remove n-th character from a string
- How to get integer values from a string in Python?
- Removing nth character from a string in Python program
- How to remove the last character from a string in Java?
- Check if max occurring character of one string appears same no. of times in other in Python
- Java program for removing n-th character from a string
