About Python - "Module and Functions" | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 4

About Python - "Module and Functions"

In the argument lesson, they have put this code def print_sum_twice(x, y): print(x + y) print(x + y) print_sum_twice(5, 8) But shouldn't we have to use print(str(x+y))? I thought the print could not print an integer.

25th Oct 2017, 1:30 PM
André
André - avatar
5 Antworten
+ 3
25th Oct 2017, 2:09 PM
Chrizzhigh
Chrizzhigh - avatar
+ 2
print() calls the magic string method from the object given to it. so not onky can you print strings but also ints floats dictionaries and lists
25th Oct 2017, 2:01 PM
Chrizzhigh
Chrizzhigh - avatar
+ 2
https://www.python-course.eu/python3_magic_methods.php here is more about magic method
25th Oct 2017, 2:02 PM
Chrizzhigh
Chrizzhigh - avatar
+ 2
Thanks, man
25th Oct 2017, 4:05 PM
André
André - avatar
0
print() will take any type of variable including integers just fine. No magic method needed!
9th Nov 2017, 4:32 PM
Alan Beveridge
Alan Beveridge - avatar