Lowercase in Python | String lower() Method
In Python, there are multiple ways to convert a string to lowercase. Following are a few of the most common methods:
Using the lower() method
The lower() method returns a string in all lowercase characters.
Using the casefold() method
The casefold() method returns a string in all lowercase characters and is similar to lower(). The difference between them is that casefold() is more aggressive in its conversion and can handle certain characters that lower() cannot.
Using the str.lower() method
This method is similar to using lower() method, but instead of calling the method on the string itself, you can call it as a function of str class.
Using the map() function
The map() function applies a function to each element of an iterable. you can use map() function to apply lower() method to each character of the string.
Using a for loop
You can loop over each character in the string and convert it to lowercase.
Using list comprehension
You can use list comprehension to create a new list of lowercase characters and join them together to form the new lowercase string.
All of the above methods will convert the string to lowercase in Python.
Lowercase first character of String in Python
To lowercase the first character of a string in Python, you can use the the lower() method.
In the above example,take the first character of the string using slicing (my_string[:1]), convert it to lowercase using the lower() method, and concatenate it with the rest of the string (my_string[1:]). Note that the second letter of the string remains capitalized in this example.
- Python print statement "Syntax Error: invalid syntax"
- Installing Python Modules with pip
- How to get current date and time in Python?
- No module named 'pip'
- How to get the length of a string in Python
- ModuleNotFoundError: No module named 'sklearn'
- ModuleNotFoundError: No module named 'cv2'
- Python was not found; run without arguments
- Attempted relative import with no known parent package
- TypeError: only integer scalar arrays can be converted to a scalar index
- A value is trying to be set on a copy of a slice from a DataFrame
- ValueError: setting an array element with a sequence
- Indentationerror: unindent does not match any outer indentation level
- Valueerror: if using all scalar values, you must pass an index
- ImportError: libGL.so.1: cannot open shared object file: No such file or directory
- Python Try Except | Exception Handling
- Custom Exceptions in Python with Examples
- Python String replace() Method
- sqrt Python | Find the Square Root in Python
- Read JSON file using Python
- Binary search in Python
- Defaultdict in Python
- Int Object is Not Iterable – Python Error
- os.path.join in Python
- TypeError: int object is not subscriptable
- Python multiline comment
- Typeerror: str object is not callable
- Python reverse List
- zip() in Python for Parallel Iteration
- strftime() in Python
- Typeerror: int object is not callable
- Python List pop() Method
- Fibonacci series in Python
- Python any() function
- Python any() Vs all()
- Python pass Statement
- Modulenotfounderror: no module named istutils.cmd
- Append to dictionary in Python : Key/Value Pair
- timeit | Measure execution time of small code
- Python Decimal to Binary
- GET and POST requests using Python
- Difference between List VS Set in Python
- How to Build Word Cloud in Python?
- Binary to Decimal in Python
- Modulenotfounderror: no module named 'apt_pkg'
- Convert List to Array Python