Python单双引号转义符输出
一、单引号输出
1 2 | #单引号 print ( 'Hello,world' ) |
结果:Hello,world
二、双引号输出
1 2 | #双引号 print ( "Hello,world" ) |
结果:Hello,world
三、单双混搭
1 2 3 | #单双混搭 print ( "'Hello,world'" ) print ( '"Hello,world"' ) |
结果:
'Hello,world'
"Hello,world"
四、单行多行注释
1 2 3 4 5 6 7 8 9 10 | #这个也是打印 单行注释 # 这个也是单行注释 control+/ print ( '"hello,python1"' ) ''' 下边都是打印 我是正正 我是多行注释 ''' print ( "'hello,python2'" ) print ( "'hello,python3'" ) |
结果:
"hello,python1"
'hello,python2'
'hello,python3'
五、占位符输出
1 2 3 4 5 | #占位符 # s string类型 d 数字类型 print ( "我的名字是%s" % ( '死神' )) print ( "我的名字是%s,我的老婆是%s,我今年%d岁,我的身高是%d" % ( '死神' , '小罗' , 29 , 179.5 )) print ( "我的名字是%s,我的老婆是%s,我今年%d岁,我的身高是%.2f" % ( '死神' , '小罗' , 29 , 179.545484 )) |
输出结果:我的名字是死神 我的名字是死神,我的老婆是小罗,我今年29岁,我的身高是179 我的名字是死神,我的老婆是小罗,我今年29岁,我的身高是179.54
六、转义符
1 2 | # 换行注释 \n=newline \n print ( "ABC\nDEF" ) |
ABC
DEF
1 2 3 4 5 6 | # 引号 \' \" print ( ' \" \' ' ) print ( 'I\'m man' ) print ( "I'm man" ) print ( "c:\\windows\\python" ) print ( "c:\windows\python" ) |
输出结果:
" '
I'm man
I'm man
c:\windows\python
c:\windows\python
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)