+ 1

Def function in python

Just learned about using DEF and I’m doing some tests, with the following input: Def user_info(): Age = input(“what’s your age?”) Name = input(“what’s your name?) Print(user_info) And it’s working fine i just wanna know why by the end of the outputs I’m getting a “none” printed as well.

21st Jan 2019, 7:49 PM
Victor Biscio
Victor Biscio - avatar
6 odpowiedzi
+ 5
You need to add return statement.
21st Jan 2019, 8:38 PM
Hubert Dudek
Hubert Dudek - avatar
+ 5
def user_info(): age = input("what's your age? ") name = input("what's your name? ") return name, age print(user_info())
21st Jan 2019, 10:22 PM
Hubert Dudek
Hubert Dudek - avatar
+ 4
By the way thanks to that topic I realized that code playground for python doesn't work when there are 2 inputs.
22nd Jan 2019, 12:21 AM
Hubert Dudek
Hubert Dudek - avatar
+ 3
It does, sort of. You have to enter both inputs at the same time, e. g. 69 [hit 'enter'] David [hit 'submit'] 😁
22nd Jan 2019, 8:06 AM
David Ashton
David Ashton - avatar
+ 1
because by default, each function returns a None.
21st Jan 2019, 7:53 PM
Yan
Yan - avatar
+ 1
Hubert Dudek can you give me an example?
21st Jan 2019, 8:49 PM
Victor Biscio
Victor Biscio - avatar