+ 3

What happens if i multiply a string by a negative number🤔🤔

Ace: Fixed for language tag

11th Jul 2020, 4:41 PM
Amith Mathew
Amith Mathew - avatar
9 Respuestas
+ 5
I believe a possible behind-the-scenes for the multiplication in question looks like: res="" for i in range(number): res+=string print(res) Since range(number) has nothing when number<=0, res is just a blank.
11th Jul 2020, 5:02 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
Try it. It will not output anything. Like if you multiply a string with 0,it results in "No output". Same case here... It will not output anything
11th Jul 2020, 4:45 PM
Arctic Fox
Arctic Fox - avatar
+ 4
Amith Mathew Yeah good question. Multiplying a string by a number is called replication in python. And for replication there are some conditions like 1. One of two data types must be String and the second one must be a Natural number. If we try to replicate a string by multiplying it by an another string then it will throw an error. But what if we multiply it by a negative number. Lets see If we multiply a negative number or zero to string then it will return an empty string and the output screen will show No output Let's do it practically now https://code.sololearn.com/csM9wVmZXmMU/?ref=app I hope it helped you. For any querry mention me . Thank you.
11th Jul 2020, 4:55 PM
Akshay Panwar
Akshay Panwar - avatar
+ 3
Thank you Prometheus
11th Jul 2020, 5:05 PM
Amith Mathew
Amith Mathew - avatar
+ 2
If you do a = "this" print(a* -2) >>> #prints nothing Same is with *0, *-1, *-2 and so on.
12th Jul 2020, 5:39 AM
Sven_m
Sven_m - avatar
+ 1
Rishab, Akshay,Ace thanks guys appreciate it
11th Jul 2020, 5:01 PM
Amith Mathew
Amith Mathew - avatar
+ 1
It prints nothing, basically an empty string!
12th Jul 2020, 9:47 AM
Nikita
Nikita - avatar