0

Quick and basic question

For the code: def beCareful (): print 'Be Careful!' print beCareful() Why does it print: Be Careful! None Why is the "None" there?

31st Jan 2017, 5:53 AM
Dan C
Dan C - avatar
2 Answers
+ 3
the function beCareful() declared above returns nothing and instead have the statement to print the String 'Be Careful!'. Since you are asking Python to print the function, this actually means you are asking Python to print the returned value from the function, which technically is nothing since you did not return anything. So, what it does is it prints the String , and then 'None' since there is nothing to be printed. If you do not want the 'None', beCareful() alone is fine.
31st Jan 2017, 6:40 AM
Deddy Tandean
+ 2
beCareful() is a function, but returns no value, thus None. When you call "print beCareful()", you're asking Python to print the returning value of beCareful. If you don't want to have "None" printed, you should call just "beCareful()", without "print".
31st Jan 2017, 6:10 AM
Álvaro