# Variables 变量


# Grade 2 ( 5-7岁 ) 要掌握的程度

Information in the real world can be represented in computer programs. Programs store and manipulate data, such as numbers, words, colors, and images. The type of data determines the actions and attributes associated with it.

Different actions are available for different kinds of information. For example, sprites (character images) can be moved and turned, numbers can be added or subtracted, and pictures can be recolored or cropped.

Crosscutting Concept: Abstraction Connection Within Framework: K–2.Data and Analysis.Storage

现实世界中的信息可以用计算机程序表示. 程序可以存储和操作各种数据, 包括数字、文字、颜色、图像. 数据的类型决定了与之相关的操作和属性.

不同种类的信息有不同的操作. 比如说, 图像可以移动和转动、数字可以被加减、图片可以被重新着色或者剪裁.


# Grade 5 ( 8-11岁 ) 要掌握的程度

Programming languages provide variables, which are used to store and modify data. The data type determines the values and operations that can be performed on that data.

Variables are the vehicle through which computer programs store different types of data. At this level, understanding how to use variables is sufficient, without a fuller understanding of the technical aspects of variables (such as identifiers and memory locations). Data types vary by programming language, but many have types for numbers and text. Examples of operations associated with those types are multiplying numbers and combining text. Some visual, block-based languages do not have explicitly declared types but still have certain operations that apply only to particular types of data in a program.

Crosscutting Concept: Abstraction Connection Within Framework: 3–5.Data and Analysis.Storage

编程语言提供“变量 / variable”, 用于存储和修改数据. 数据的类型决定了可以对该数据进行哪些操作.

“变量”是计算机程序存储不同类型数据的载体. 对于这个阶段的学生, 了解如何使用变量就足够了, 不需要了解变量的具体技术细节 (比如标识符、内存位置 ).

数据类型因编程语言而有所不同, 但大多数编程语言都有“数字”类型和“文本”类型. 因为数据类型决定了数据可以进行的操作, 所以数字类型的数据可以进行加减乘除, 而文本类型的数据可以进行文本连接但不能进行加减乘除.

可视化的、基于积木块的编程语言没有明确声明数据的类型(比如 Scratch 编程语言), 但是可视化编程语言中, 不同的数据仍然有只适用于该数据类型的操作.


# Grade 8 ( 11-14岁 ) 要掌握的程度

Programmers create variables to store data values of selected types. A meaningful identifier is assigned to each variable to access and perform operations on the value by name. Variables enable the flexibility to represent different situations, process different sets of data, and produce varying outputs.

At this level, students deepen their understanding of variables, including when and how to declare and name new variables. A variable is like a container with a name, in which the contents may change, but the name (identifier) does not. The identifier makes keeping track of the data that is stored easier, especially if the data changes. Naming conventions for identifiers, and thoughtful choices of identifiers, improve program readability.

The term variable is used differently in programming than the way it is commonly used in mathematics: a program variable refers to a location in which a value is stored, and the name used to access the value is called the identifier. A program variable is assigned a value, and that value may change throughout the execution of the program. Mathematicians typically do not make a distinction between a variable and the variable name. A mathematics variable often represents a set of values for which the statement containing the variable is true.

Crosscutting Concept: Abstraction Connection Within Framework: 6–8.Data and Analysis.Storage

程序员创建“变量”来存储数据. 计算机为每个变量分配了标识符, 方便按照标识符来访问数据和执行对该数据的操作. 正因为有“变量”这个工具, 程序才能够灵活地适用于不同的情况、处理不同的数据, 并由此产生不同的输出结果.

对于这个阶段的学生, 需要加深对“变量”的理解, 需要掌握何时以及如何声明和命名新的变量.

变量就像一个有名字的容器, 里面的内容可能会改变, 但名字 (标识符) 不会改变. “标识符”使得调用存储的数据更加容易, 即使变量里面的数据已经发生了变化. 注意, 对于标识符的命名有通用的惯例, 在命名变量时必须遵守这些惯例, 并且尽可能选择有意义的名称, 来提高程序的可读性.

“变量”一词在编程中的含义和数学中的含义并不相同: 程序的”变量“指的是一个存储数据的位置, 而用于访问该数据的变量名称被称为”标识符“. 程序中的变量会被分配一个值, 这个值在程序运行过程中都可能发生变化. 而数学家通常不对”变量“和”变量名称“进行区分, 数学的”变量“通常代表一组数值之间的关系. 对于这些数值而言, 包含该变量的语句是真的. #todo


# Grade 12 ( 14-18岁 ) 要掌握的程度

Data structures are used to manage program complexity. Programmers choose data structures based on functionality, storage, and performance tradeoffs.

A list is a common type of data structure that is used to facilitate the efficient storage, ordering, and retrieval of values and various other operations on its contents. Tradeoffs are associated with choosing different types of lists. Knowledge of advanced data structures, such as stacks, queues, trees, and hash tables, is not expected. User-defined types and object-oriented programming are optional concepts at this level.

Crosscutting Concepts: Abstraction; System Relationships Connection Within Framework: 6–8.Computing Systems.Hardware and Software

数据结构被用来管理程序的复杂性, 程序员通过权衡功能、存储、性能来选择数据结构.

“列表”是一种常见的数据结构类型, 它被用来有效地存储、排序、检索数据. 在不同场景下, 可以选择不同类型的列表.

对于这个阶段的学生, 对高级数据结构不做要求, 比如堆栈、队列、树、哈希表. 对于用户自定义的类型以及面向对象编程是可选的概念, 学生可以掌握, 也可以不掌握.