+ 7

[Solved] Why coming None in output with ASCII values?

I am printing the ASCII values of alphabets but I also am also getting None? Does anyone know the reason? See the Code below def printAscii(): str = "abcdefghijklmnopqrstuvwxyz" for i in str: #print(i, end = ' ') print(ord(i), end = ' ') print(printAscii())

23rd Jul 2020, 2:27 PM
A͢J
A͢J - avatar
10 ответов
+ 10
because youre printing a function that prints. and the function doesnt return anything, so it prints None after it takes care of the call to print out all of the ascii values. instead of print(print_ASCII()) just print_ASCII()
23rd Jul 2020, 2:37 PM
Slick
Slick - avatar
+ 5
DAC 🎯 [Exams] TheWh¡teCat 🇧🇬 $hardul B ♤♢☞ 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 ☜♢♤ Slick Namit Jain Thanks to all. I didn't notice that I am printing function also but Java doesn't gives output like in python.
23rd Jul 2020, 4:06 PM
A͢J
A͢J - avatar
23rd Jul 2020, 2:41 PM
$hardul B
$hardul B - avatar
+ 4
DAC 🎯 [Exams] I did that purposefully! print("hello world") Will give only hello world But print(print("hello world")) Will give hello world None
23rd Jul 2020, 2:58 PM
Namit Jain
Namit Jain - avatar
23rd Jul 2020, 2:32 PM
Namit Jain
Namit Jain - avatar
+ 3
DAC 🎯 [Exams] , because there are two print statements => one in the function and the other outside when calling the function. So when the function finishes the last thing it does is print inside a print, but print return None and the outside print shows that result.
23rd Jul 2020, 2:58 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar