Python Forum

Full Version: Is there another way to solve this code but still using for loop?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def first(s):
""" Determine if a string contains a lowercase or uppercase r
Test data:
input: 'garden'
output: 'r'
Params: s(string)
Returns: (string) lowercase r
"""
c = 'r'
for c in s:
if c == 'r':
return("The string contains a lowercase r")
else:
pass
s= 'garden'
print(first(s))
Hello!
Looks like a homework.
See str.islower(). c is a string object so it has islower method.