Python学习第一天-变量和字符串(上)

[复制链接]
15271953841 发表于 2024-1-25 22:00:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
Python 3.12.1 (tags/v3.12.1:2305ca5, Dec  7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>x=3
>>>print(x)
3
>>>loveyou1314=1314
>>>520baby=520
SyntaxError: invalid decimal literal(变量名不能有数字开头)
>>>幸运数=588
>>>print(幸运数)
588
>>>name="小甲鱼"
>>>print(name)
小甲鱼
>>>name="老乌龟"
>>>print(name)
老乌龟
>>>x=3
>>>y=5
>>>y=x
>>>print(y)
3
>>>x=y=3
>>>x
3
>>>y
3
>>>x=3
>>>y=5
>>>z=x
>>>x=y
>>>y=z
>>>print(x,y)
5 3
x=3
y=5
x,y=y,x
>>>print(x,y)
5 3
>>>print('I love China,')
I love China,
>>>print("I love fishC.")
I love fishC.
>>>print('Let's go.')
      
SyntaxError: unterminated string literal (detected at line 1)(中间的单引号和两侧的单引号混淆)
>>>print("Let's go.")
      
Let's go.
>>>print('"Life is short,let's learn Python."')
      
SyntaxError: unterminated string literal (detected at line 1) (中间的单引号和两侧的单引号混淆,两侧的双引号只起强调作用)

>>>print('\"Life is short,let\'s learn Python.\"')
      
"Life is short,let's learn Python."
>>>print('I love China.\nI love fishC.')
     ( 增加了3个转义字符\’)
I love China.
I love fishC.
加了一个转义字符换行\n)
关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:admin@discuz.vip

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|鄂ICP备13007585号-4

在本发帖
关注公众号
QQ客服返回顶部