Can’t multiply sequence by non-int of type ‘float’
What is TypeError ?
TypeError happens when you try to execute an operation or call an operator on something with the wrong type
The Above code returns the
TypeError: can only concatenate str (not "int") to str
- This kind of operation is not allowed in python
- You Can’t concatenate the string with an integer
print('Hi'+str(50)) # Hi50
print(2.0 * 'Hi From UK')
typeerror: can’t multiply sequence by non-int of type ‘float’
The Above code returns the error
TypeError : can't multiply sequence by non-int of type 'float'
- You Cannot multiply float value & a string.
- Multiplication operator doesn’t work between string & floating-point value
How do we solve this??
This TypeError is one of the easiest to solve. Accept the user input as an integer instead of a string.
r = int(input("Radius:")) # input print('Circumference = ',2 * 3.14 * r)
Radius:5 Circumference = 31.400000000000002
- The Above Code is completely allowed in python , You get the result
Python List Example
list = ['C','J'] print(int(2.0) * list) # ['C', 'J', 'C', 'J']
Python Tuple Example
tuple = ( 44 , 55 , 66 ) print(int(2.0) * tuple) # (44, 55, 66, 44, 55, 66)
Convert the floating-point value with the help of python inbuild function
- Make sure that all string values are converted to a floating-point number