栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

打印组合的字符串和数字

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

打印组合的字符串和数字

不带括号的情况下 使用 print函数 可用于旧版本的Python,但 Python3不再支持该功能
,因此您必须将参数放在括号内。但是,有一些变通方法,如对该问题的答案所述。由于对Python2的支持已于2020年1月1日结束,因此
答案已修改为与Python3兼容

您可以执行以下任一操作(并且可能还有其他方法):

(1)  print("First number is {} and second number is {}".format(first, second))(1b) print("First number is {first} and number is {second}".format(first=first, second=second))

要么

(2) print('First number is', first, 'second number is', second)

(注意:与逗号分开后,空格会自动添加)

要么

(3) print('First number %d and second number is %d' % (first, second))

要么

(4) print('First number is ' + str(first) + ' second number is' + str(second))

如果可能,最好使用
format() (1 /
1b)。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/610544.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号