解决使用python print打印函数返回值多一个None的问题
作者:gz-郭小敏 时间:2021-08-22 07:52:09
根本原因:
python定义函数时,一般都会有指定返回值,如果没有显式指定返回值,那么python就会默认返回值为None
我们输入的代码如下:
def test():
print('aaa')
print(test())
相当于执行了:
def test():
print('aaa')
return None
print(test())
如果不想要有None,那么就要添加返回值
def test():
return 'ccc'
print(test())
补充知识:python中如何实现print函数的多值匹配
方法:直接使用%(元组)进行多值匹配,如:
a=1
b=2
print("多值匹配:%d%d"%(a,b))
运行结果:
来源:https://blog.csdn.net/github_39570717/article/details/88557432
标签:python,print,None
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现从文件中加载数据的方法详解
2022-05-28 12:41:31
![](https://img.aspxhome.com/file/2023/0/107960_0s.png)
php让json_encode不自动转义斜杠“/”的方法
2023-08-19 17:04:28
基于Python函数的作用域规则和闭包(详解)
2023-09-03 09:00:28
Python QQBot库的QQ聊天机器人
2022-03-18 23:29:30
![](https://img.aspxhome.com/file/2023/0/64720_0s.jpg)
在python中将字符串转为json对象并取值的方法
2022-12-19 02:22:37
Python中的通函数numpy.ufunc详解
2023-09-03 22:52:08
Python 关于反射和类的特殊成员方法
2021-10-16 19:30:13
详细解读php的命名空间(一)
2023-06-19 08:02:59
python中验证码连通域分割的方法详解
2022-09-30 11:04:00
python安装cx_Oracle和wxPython的方法
2022-07-31 11:33:04
![](https://img.aspxhome.com/file/2023/1/93451_0s.png)
解决Keras 与 Tensorflow 版本之间的兼容性问题
2022-08-04 08:18:53
JSONObject.toString
2008-03-09 19:12:00
TensorFlow 滑动平均的示例代码
2023-10-25 15:41:28
MYSQL教程:MySQL Show命令
2009-12-20 17:54:00
Python获取江苏疫情实时数据及爬虫分析
2022-09-19 02:12:30
![](https://img.aspxhome.com/file/2023/9/95439_0s.jpg)
如何实现全文检索?
2010-05-24 18:24:00
什么是Ajax及Ajax的优势
2007-09-07 09:56:00
![](https://img.aspxhome.com/file/UploadPic/up/2007091821580144.jpg)
python之OpenCV的作用以及安装案例教程
2021-11-27 07:14:20
Python进度条的制作代码实例
2022-01-01 23:17:34
Python安装jieba库详细教程
2023-05-09 12:18:19
![](https://img.aspxhome.com/file/2023/5/84935_0s.png)