python string in lowercase code example
Example 1: python lowercase
string = string.upper()
string = string.lower()
string.islower()
string.isupper()
Example 2: python convert string to lowercase
# By Alan W. Smith and Petar Ivanov
s = "Kilometer"
print(s.lower())
Example 3: python string to lower
str = 'heLLo WorLD'
print(str.lower())
# hello world
Example 4: python - convert to lowercase
students = ['Sarah', 'Mary', 'Anna', 'Charlotte']
# Option 1
students_lower = map(lambda x: x.lower(), students) # map() produces a generator
print(list(students_lower)) # give all elements of the generator
# Option 2
students_lower = [student.lower() for student in students] # list comprehension
# Option 3
students_lower = (student.lower() for student in students) # generator comprehension
print(list(students_lower))
Example 5: how to check if a string is lowercase in python
string = "python"
string.islower()
#returns true or false
#or we can use this
string == string.lower()
#returns true or false