Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help!!
#1
1
2
3
4
5
6
7
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?
buran write Feb-22-2024, 12:00 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
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:
1
2
3
4
5
6
7
8
9
10
11
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
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply
#3
In addition to what it has previously said, that's the return content which is returned using print (None by default if not specified)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020