Skip to content Skip to sidebar Skip to footer

Error With Print: Unsupported Operand Type(s) For +: 'nonetype' And 'str'

I have code for concatenation of two string but it is showing me an error. Here is the code : Name = 'Praveen kumar' print (Name)+'Good boy' Error message : unsupported operand t

Solution 1:

print is a function, returning None.

So when you write

print(Name) + "Good boy"

You are actually adding the return value of the function call (i.e. None) to the string.

What you wanted instead was probably:

print(Name, "Good boy")

Solution 2:

You are printing Name and then adding the string Good boy to it, you need to enclose your addition within the function call.

print(Name) will return None (it is a function which defines no return value) which is why you're getting the unsupported operand... error.

The code below will achieve what you want.

Name = "Praveen kumar"print(Name + "Good boy")

However note that there will be no space between Name and 'Good boy'. If you want a space then you can use print(Name, "Good boy") as the default separator is sep = ' ', meaning that a space will be added between your arguments.

Post a Comment for "Error With Print: Unsupported Operand Type(s) For +: 'nonetype' And 'str'"