Python 在执行定义的语句后,";无”;印刷两次
当我运行下面的代码并完成整个Python 在执行定义的语句后,";无”;印刷两次,python,function,Python,Function,当我运行下面的代码并完成整个request功能,然后回答n到reqSecPass部分时,它会打印bye,后面是两行,表示None。我如何消除这种情况 您可以看到,再见语句是独立的,我不确定这是否有区别 def goodbye(): print('Good Bye!') def request(): reqPass = input('Which password would you like?[Google, Twitter, Reddit, Computer]') #s
request
功能,然后回答n
到reqSecPass
部分时,它会打印bye
,后面是两行,表示None
。我如何消除这种情况
您可以看到,再见
语句是独立的,我不确定这是否有区别
def goodbye():
print('Good Bye!')
def request():
reqPass = input('Which password would you like?[Google, Twitter, Reddit, Computer]')
#still need to figure out dictionary manipulation so this is a temporary sytem.
if(reqPass == 'google' or reqPass == 'google'):
print('________________')
print('Pass: GOOGLEPASSWORDHERE')
print('________________')
reqSecPass = input('Request another password?[y/n]')
if(reqSecPass == 'y' or reqSecPass == 'Y'):
print(another())
else:
print(goodbye())
elif(reqPass == 'twitter' or reqPass == 'Twitter'):
print('_________________')
print('User: TWITTERUSERNAMEHERE')
print('Pass: TWITTERPASSWORDHERE')
print('________________')
reqSecPass = input('Request another password?[y/n]')
if(reqSecPass == 'y' or reqSecPass == 'Y'):
print(another())
else:
print(goodbye())
elif(reqPass == 'computer' or reqPass == 'Computer'):
print('________________')
print('Pass: COMPUTERPASSWORDHERE')
print('________________')
reqSecPass = input('Request another password?[y/n]')
if(reqSecPass == 'y' or reqSecPass == 'Y'):
print(another())
else:
print(goodbye())
elif(reqPass == 'reddit' or reqPass == 'Reddit'):
print('_________________________')
print('User: REDDITUSERNAMEHERE')
print('Pass: REDDITPASSWORDHERE')
print('________________')
reqSecPass = input('Request another password?[y/n]')
if(reqSecPass == 'y' or reqSecPass == 'Y'):
print(request())
else:
print(goodbye())
print('_____This is a password keeper_____')
#checking if the user has an account
actCheck = input('Do you already have an account?')
if(actCheck == 'Yes' or actCheck == 'yes'):
#asking for user's name and password
yourUser = input('___What is your Username?___')
yourPass = input('___What is your Password?___')
if(yourUser == 'ari' and yourPass == 'rycbar1234'):
dirCheck = input('Account settings?[y,n]')
if(dirCheck == 'y' or dirCheck == 'Y'):
print('this function is not working yet!')
actSetCheck = input('Change username or password?')
if(actSetCheck == 'user' or actSetCheck == 'User' or actSetCheck == 'Username' or actSetCheck == 'username'):
yourUser = input('What would you like your new username to be?')
elif(actSetCheck == 'pass' or actSetCheck == 'Pass' or actSetCheck == 'password' or actSetCheck == 'Password'):
yourPass = input('What would you like your new username to be?')
elif(dirCheck == 'n' or dirCheck == 'N'):
print(request())
else:
print('Incorrect Username or password')
您正在打印函数的返回值。所有函数都返回
None
(当您不使用显式return
语句时的默认返回值)
从函数调用中删除print()
语句,而不是:
print(another())
# ...
print(goodbye())
# ...
print(request())
只用
another()
# ...
goodbye()
# ...
request()
或者,让函数返回要打印的字符串:
def goodbye():
return 'Good Bye!'
print(goodbye())
虽然可能不值得只使用函数返回单个字符串值。您正在打印函数的返回值。所有函数都返回
None
(当您不使用显式return
语句时的默认返回值)
从函数调用中删除print()
语句,而不是:
print(another())
# ...
print(goodbye())
# ...
print(request())
只用
another()
# ...
goodbye()
# ...
request()
或者,让函数返回要打印的字符串:
def goodbye():
return 'Good Bye!'
print(goodbye())
虽然可能不值得只使用函数来返回单个字符串值。您正在打印没有显式
return
语句的函数返回的值。默认情况下,此函数返回的值为None
。您正在打印此值
有时尝试使用
return
语句,而不是总是打印,例如return“再见!”
您正在打印没有显式return
语句的函数返回的值。默认情况下,此函数返回的值为None
。您正在打印此值
有时尝试使用
return
语句,而不是总是打印,例如return“再见!”
似乎不返回任何内容的函数返回无
,例如再见
。也就是说,debye()==None
。函数的默认返回值是None
您正在函数中打印,然后在调用前后使用print
调用函数。似乎不返回任何内容的函数返回None
,例如debye
。也就是说,bye()==None
。函数的默认返回值是None
您正在函数中打印,然后在调用前后使用print
调用函数。谢谢!我做了您建议的编辑,但是,它仍然在打印“无”,但现在只打印了一次。@AriMadian:所以您有另一个print()
在某处打印返回值。我没有详细浏览你所有的代码。谢谢!我做了您建议的编辑,但是,它仍然在打印“无”,但现在只打印了一次。@AriMadian:所以您有另一个print()
在某处打印返回值。我没有详细浏览你所有的代码。