🐸

文字与数字

Python 基础python-basics-04-words-and-numbers
奖励: 50 XP
|

不同的魔法种类

Hoppy 发现 5"5" 看起来很像,但它们是完全不同的魔法。

魔法实验

print(5 + 5)      # 结果: 10 (数学运算)
print("5" + "5")  # 结果: "55" (文字拼接)
  • 整数 (int): 用来计算的数字。没有引号。

  • 字符串 (str): 用来阅读的文字。必须有引号。

你的任务

1
数学加法

创建一个变量 math_result,让它等于 10 + 10

2
文字加法

创建一个变量 text_result,让它等于 "10" + "10"

3
观察结果

打印这两个变量,看看区别。

参考答案
点击展开
math_result = 10 + 10
text_result = "10" + "10"

print(math_result)
print(text_result)
高级技巧
想更进一步?点击展开

你可以用 type() 魔法查看任何盒子的类型。

print(type(5))
print(type("5"))

运行这段代码,看看它们有什么不同!

pymain.py
Loading...
终端输出
Terminal
Ready to run...