Python中不同类型的内容怎么一起输出
who = '我的'
action = '是'
destination = '镜像世界'
number = 153
code = '通行密码'
对他们一起输出,如果直接用print(who+action+destination+number+code)
运行代码报错
方法一:在输出时使用类型转换,负责转换数据类型的函数一共有3种:str()、 int()和float()
print(who+action+destination+str(number)+code)
方法二:直接用引号把数字括起来
print(who+action+destination+‘153’+code)
方法三:使用format
print('{0}{1}{2}'.format(number,code,action))
版权声明:本文为u011135803原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。