What is the difference? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

What is the difference?

num="Data" mult=num*4 print(mult) #please, answer, what is the difference? print("Data"*4)

25th Aug 2022, 9:51 AM
Artem Topornytskyi
Artem Topornytskyi - avatar
3 Réponses
+ 6
The output is the same, but in the 1st example DataDataDataData is assigned to a variable, in the 2nd it is created in print without storing it in a variable.
25th Aug 2022, 9:54 AM
Lisa
Lisa - avatar
+ 4
Like Lisa says: using 'mult' you can re-use it later, but when you only print it, it's gone once you do it.
25th Aug 2022, 9:56 AM
Monika
+ 3
For the answer, there is no difference as both 'print' are the same. But it is better to use your 'mult' as a variable and then print it, otherwise in a longer code you will have to change every single 'print' statement, not just your variable.
25th Aug 2022, 9:54 AM
Monika