+ 1
How to print out only lowercase letters in a word?
How would you search and print out all letters that are lowercase? My guess was this, but it doesnt work... def any_lowercase2(s): for i in range(len(s)): if s[i] == s[i].islower(): print(s[i]) i +=1 any_lowercase2('HELP') any_lowercase2('help') any_lowercase2('HeLP')
2 Respostas
+ 4
Try it like this, islower() is used for checking whether or not a char is in lower case, if s[i].islower(): gets true if the char(s[i]) is in lower case.
def any_lowercase2(s):
for i in range(len(s)):
if s[i].islower():
print(s[i],end="")
i +=1
Hth, cmiiw
+ 3
@Trump I'm still learning Python, the i+=1 came with original code, yeah your code does the job well. Thanks for pointing it out :)