Basically, we cannot add a string and a number, but we can definitely multiply a string and a number. When a string is multiplied with an integer n, the string is repeated n times. The * operator is known as the string repetition operator.
Python String Repetition Examples
Example: 1
a="Hello"*5 print(a)
Output:
HelloHelloHelloHelloHello
We cannot multiply two strings. Also, we cannot multiply a string with a floating-point number.
Example: 2
a="Hello" b="World" c=a*b print(c)
Output:
Error
Example: 3
a="Hello"*5.0 print(a)
Output
Error
Leave a comment