0Pricing
Mojo Academy · 课时

字符串与文本

存储并组合文本值

字符串与文本 是 CoddyKit 上的免费 Mojo Academy 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Mojo Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Mojo Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Text Is a String

Any sequence of characters, like a name or a message, is a String. It is how programs hold human-readable text. 💬

Make a String

Wrap text in double quotes to create a String, then store it in a var so you can reuse the text later.

var name = "Ada"

Single or Double Quotes

Mojo accepts both quote styles. Pick the one that lets your text stay clean, like single quotes around a phrase with a quote inside.

var word = 'hello'

Joining Text with +

Put two Strings together using +. This is called concatenation and it builds a longer string from pieces.

var greeting = "Hi, " + name

Mind the Spaces

Concatenation glues text exactly as written. Add a space inside a String so words do not collide when joined.

var full = "Ada" + " " + "Lovelace"

Printing Text

print sends a String to the screen. It is your quickest way to see what a String currently holds.

print("Hello, world")

Empty and Long Strings

A String can be empty ("") or hold a whole sentence. Length is up to you; the type stays the same either way.

var blank = ""

Numbers Are Not Text

"42" is a String, while 42 is an Int. They look alike but behave differently, so keep text and numbers distinct.

var label = "42"

Turning a Number into Text

To join a number into a message, convert it with String first so the + has two strings to combine.

var msg = "Score: " + String(score)

Strings Describe Your Program

Labels, prompts, and messages are all Strings. Clear text makes your output friendly for the person reading it.

Text Powers Communication

From greetings to error messages, Strings carry meaning to users. Mastering text is half of writing useful programs.

Quick Check

You have a number in score and want to put it inside a text message. What do you do first?

Recap

A String holds text in quotes, joins with +, and prints to the screen. Convert numbers to String before mixing them in. 🎯

常见问题解答

「字符串与文本」课时是免费的吗?

是的 — 「字符串与文本」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Mojo Academy 课程的其余内容,请升级到 CoddyKit PRO。 Mojo Academy 课程共包含 4 节课。

「字符串与文本」这节课中我会学到什么?

存储并组合文本值 你通过在浏览器中直接运行的动手代码来练习 Mojo Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Mojo Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Mojo Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「字符串与文本」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Mojo Academy 课中编写并运行代码吗?

能。每节 Mojo Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 使用 var 声明值
  2. Int、Float 与 Bool
  3. 字符串与文本
  4. 有帮助的类型注解
← 返回 Mojo Academy