What is a str means in pyhton like print(str(i)x i) means | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is a str means in pyhton like print(str(i)x i) means

12th Feb 2020, 10:02 AM
Hamza Ali
Hamza Ali - avatar
3 Answers
+ 5
str(i) transforms the i variable to string type. You can multiply a string by a whole number then the string is repeated as many times as the number. But multiplication symbol is * and not x print(str(i) * i) https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2427/
12th Feb 2020, 10:12 AM
Tibor Santa
Tibor Santa - avatar
+ 2
str(i) converts i into string. (Please be strict with syntax rules, x is not same than *, but I assume you're using *) Multiplying a string with integer i would cause the string to be added to *itself* i - 1 times. "5" * 5 = "5" + "5" + "5" + "5" + "5" ="55555".
12th Feb 2020, 10:13 AM
Seb TheS
Seb TheS - avatar
12th Feb 2020, 10:15 AM
Seb TheS
Seb TheS - avatar