tried one | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

tried one

when i assigned x=7 and used operation print(“x”*7) ,why its showing x 7 times as output ,it should be 7 ,7 times right?

9th Feb 2019, 8:47 AM
Karan Lal
Karan Lal - avatar
2 Antworten
+ 6
print("x"*7): doesn't care about your variable x, prints "x" seven times in a row # xxxxxxx print(x*7): prints value of variable x times seven # 49 print(str(x)*7): converts value of x to a string and prints it seven times in a row # 7777777
9th Feb 2019, 9:14 AM
Anna
Anna - avatar
+ 1
"x" is a string thus it doesn't use the value of the x variable. Please check the 3rd page of the link to find out why you got that output: https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2427/?ref=app
9th Feb 2019, 12:14 PM
Lambda_Driver
Lambda_Driver - avatar