I have to check if the string contains: alphanumeric, alphabetical , digits, lowercase and uppercase characters
def fun(s):
for i in s:
if i.isalnum():
print("True")
if i.isalpha():
print("True")
if i.isdigit():
print("True")
if i.isupper():
print("True")
if i.islower():
print("True")
s=input().split()
fun(s)
why it prints true only once even though it is in a for loop
If you want to check if the whole string contains those different characters types then you don't actually have to loop through the string. You just can use the any keyword.
def fun(s):
if any(letter.isalnum() for letter in s):
print("Is alphanumeric")
if any(letter.isalpha() for letter in s):
print("Is alpha")
if any(letter.isdigit() for letter in s):
print("Is digit")
if any(letter.isupper() for letter in s):
print("Is upper")
if any(letter.islower() for letter in s):
print("Is lower")
s=str(input())
fun(s)
string = input()
print (any(c.isalnum() for c in s))
print (any(c.isalpha() for c in s))
print (any(c.isdigit() for c in s))
print (any(c.islower() for c in s))
print (any(c.isupper() for c in s))