打印错误:+ 不支持的操作数类型:“NoneType"和“str" [英] Error with print: unsupported operand type(s) for +: 'NoneType' and 'str'

查看:78
本文介绍了打印错误:+ 不支持的操作数类型:“NoneType"和“str"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有连接两个字符串的代码,但它显示了一个错误.

I have code for concatenation of two string but it is showing me an error.

代码如下:

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

错误消息:不支持 + 的操作数类型:'NoneType' 和 'str'

我该如何解决这个问题?

How can I fix this?

推荐答案

print 是一个函数,返回 None.

print is a function, returning None.

所以当你写

print(Name) + "Good boy" 

您实际上是将函数调用的返回值(即无)添加到字符串中.

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

你想要的可能是:

print(Name, "Good boy")

这篇关于打印错误:+ 不支持的操作数类型:“NoneType"和“str"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆