[Solved] Why coming None in output with ASCII values? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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
6 Respostas
+ 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
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