如何在python中使用print输出字符和变量
来源:网络收集 点击: 时间:2024-05-12首先我们输入print(hello),输出了hello;接着我们输入print(hello world!)输出了hello world!,在python里,‘’和“”效果一样。需要输入单引号时用双引号包括单引号print(100+200=,,100+200) 100+200= 300

print函数可以一次输出多个内容,各个参数之间用英文状态的,隔开。
print(hello,world!)
SyntaxError: invalid character in identifier
print(hello,world!)
hello world!
第一次显示语法错误,有非法字符就是应为输入了中文状态的逗号。

python不仅是可以输出字符,还可以输出变量和常亮的结果。
print(100+200)
300 python自动算出了100+200
print(100+200=100+200)
SyntaxError: invalid syntax 语法错误,两个参数之间应该有逗号。

如果我们想换行输入那怎么办呢?和别的变成语言一样,用转义符。
print(100+200=,\n,100+200)
SyntaxError: unexpected character after line continuation character
print(100+200=,\n,100+200)
100+200=
300
换行的转义符是\t,且转义符也要用‘’包括起来。

tab的转义符是什么呢?
print(100+200=,\tab,100+200)
100+200= ab 300
print(100+200=,\t,100+200)
100+200= 300

如果我想输出\,那就这样。
print(100+200=,\\,100+200)
100+200= \ 300

如果觉得这篇经验帮到了你,请投票、点赞鼓励我哦!谢谢啦! 如果有任何疑问,send me a message,please!
版权声明:
1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。
2、本站仅提供信息发布平台,不承担相关法律责任。
3、若侵犯您的版权或隐私,请联系本站管理员删除。
4、文章链接:http://www.1haoku.cn/art_739937.html