Search code examples
pythonpython-3.4

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 type(s) for +: 'NoneType' and 'str'

How can I fix this?


Solution

  • 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")