Python Forum

Full Version: Help!!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def hint_username(username):
    if len(username) < 3:
        print("Invalid username. Usernames must have more than 3 characters")
    else:
        print("valid username")
        
print (hint_username("charmingchand"))
OUTPUT
Output:
valid username None
I would like to know why is none appearing here?
You are using print twice. Once in the function and when calling the function.
Please use the bbtags when posting code. You should have a look at the help section on how to ask a question.

Quick example:
def afunc(arg):
    return arg

def afunc2(arg):
    print(arg)

print(afunc('I am using a return value and print'))

afunc2('Callinga function that has a print')

print(afunc2('Using both prints. This will return a None'))
Output:
I am using a return value and print Calling a function that has a print Using both prints. This will return a None None
In addition to what it has previously said, that's the return content which is returned using print (None by default if not specified)

def hint_username(username):
    if len(username) < 3:
        print("Invalid username. Usernames must have more than 3 characters")
    else:
        print("valid username")        
    return None
         
hint_username("charmingchand")
hint_username("ff")
print()

# with print
print(hint_username("\n"))
print(hint_username("ddddddddddddddddddddddddd\n"))
Output:
valid username Invalid username. Usernames must have more than 3 characters Invalid username. Usernames must have more than 3 characters None valid username None