Ayush Gupta

Ayush Gupta

2 Articles Published

Articles by Ayush Gupta

2 articles

Python: Can not understand why I am getting the error: Can not concatenate 'int' and 'str' object

Ayush Gupta
Ayush Gupta
Updated on 24-Mar-2026 156 Views

This error occurs when Python tries to concatenate (combine) an integer and a string using the + operator. Python cannot automatically convert between these data types during concatenation operations. Common Cause of the Error The error typically happens when using string formatting with %d placeholder. If you write %d % i + 1, Python interprets this as trying to add the integer 1 to the formatted string result. Incorrect Code (Causes Error) i = 5 # This causes the error - operator precedence issue print("Num %d" % i + 1) Solution: Use Parentheses ...

Read More

TypeError: __init__() takes exactly 1 argument (5 given)

Ayush Gupta
Ayush Gupta
Updated on 06-Mar-2020 230 Views

You need to indent all the method definitions so that they are under the class. exampleclass A(): def __init__(): passYou can learn more about indentation and how it needs to be used in Python here −https://www.tutorialspoint.com/python_online_training/python_lines_and_indentation.asp

Read More
Showing 1–2 of 2 articles
« Prev 1 Next »
Advertisements