← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 10640.a · 生成模型:未记录

格式参数按位置绑定

理解等级:初级

println! 的格式串可以用 {guess} 引用当前绑定。用 {} 时,后续参数中的表达式按位置填入。例如 println!("值为 {}", n + 1) 先算出表达式值,再按格式输出。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 猜数字游戏 Receiving User Input · 查看原书依据

      This line prints the string that now contains the user’s input. The {} set of curly brackets is a placeholder: think of {} as little crab pincers that hold a value in place. When printing the value of a variable, the variable name can go inside the curly brackets.

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第02章 猜数字游戏(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c02.xhtml`,块 0069) - 结论依据:原文对比命名占位符和按顺序填表达式的空花括号。 - 原始内容:This line prints the string that now contains the user’s input. The {} set of curly brackets is a placeholder: think of {} as little crab pincers that hold a value in place. When printing the value of a variable, the variable name can go inside the curly brackets.