I have
x= ['AA', 'BB', 'CC']
and I want to lower case only 'BB'
.
CodePudding user response:
To transform a string to lowercase, you use
string.lower()
To answer your question, use
x[1] = x[1].lower()
CodePudding user response:
To lower case only 'BB' in the list x, you can use a list comprehension with an if condition to check if the element is equal to 'BB'.
Here is how you can do that:
x = ['AA', 'BB', 'CC']
# Use a list comprehension with an if condition to lower case only 'BB'
x = [element if element != 'BB' else 'bb' for element in x]
# Print the modified list
print(x)
# Output: ['AA', 'bb', 'CC']
Hope this helps!
CodePudding user response:
perhaps try
` x = ['AA', 'BB', 'CC']
Str = x[1]
print(Str.lower())
`
#0 = AA, 1 = BB, 2 = CC
use 0 1 or 2 with x[NUMBER]
I hope this works for you!!