I get "None" at the end of my printed result. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: I get "None" at the end of my printed result. (/thread-20911.html) |
I get "None" at the end of my printed result. - dyshkant - Sep-06-2019 I get "None" at the bottom of my printed result and I don't know where this "None" is coming from. All works fine. Just really don't need this "None" message in the end. Your help is much appreciated. Here's my code: def str_analysis(your_input): if your_input.isdigit(): if int(your_input) > 99: print("Big number") elif int(your_input) <= 99: print("Small number") else: pass elif your_input.isalpha(): print("Your message is all Alpha characters") else: print("Your message is neither all Alpha nor all Digits") return check = str_analysis(input("Enter your message: ")) print(check) RE: I get "None" at the end of my printed result. - ThomasL - Sep-06-2019 You are assigning "check" the outcome of your function str_analysis() and the default value of return is None. So "print(check)" prints "None". Better pythonic way: DonĀ“t use print() inside a function that is doing something. Always return the value of the outcome of this "doing". def str_analysis(your_input): if your_input.isdigit(): if int(your_input) > 99: return "Big number" elif int(your_input) <= 99: return "Small number" else: pass elif your_input.isalpha(): return "Your message is all Alpha characters" else: return "Your message is neither all Alpha nor all Digits" RE: I get "None" at the end of my printed result. - buran - Sep-06-2019 str_analysys has empty return statement at the end so it will return None. Even without explicit return any function will return None if you don't specify return value. You assign that to check when you run your function it print respective message and return None. on line 18 you print that None RE: I get "None" at the end of my printed result. - dyshkant - Sep-06-2019 This makes sense. Thanks a lot to both of you! |