Variables and types
Python for IGCSE CS Lesson 2 2:14 English narration · English + 中文 subtitles burned in
Chapters
Transcript
A variable is a named box that holds a value.
变量是一个装着值的、有名字的盒子。
You put a value in with an equals sign, and that act has a name in the syllabus: assignment.
你用等号把值放进去,而这个动作在考纲里有个名字:赋值。
Worth noticing before the exam — the exam draws an arrow pointing left instead of an equals sign.
考试前值得注意一点—— 考卷上画的是一个向左的箭头,而不是等号。
Same action, different symbol, and the arrow is arguably clearer: it shows the value moving into the name.
同一个动作,不同的符号, 而且箭头可以说更清楚:它显示了值正在进入那个名字。
The syllabus names exactly five data types, and you can be asked to list them.
考纲刚好列出五种数据类型,而且可能会让你把它们写出来。
Integer is a whole number and real is a decimal.
integer 是整数,real 是小数。
Char is a single letter and string is text of any length.
char 是单个字符,string 是任意长度的文本。
And Boolean holds only true or false.
而 Boolean 只装 true 或 false。
Python calls three of those something else — int, float, str — so when the exam asks, answer with the exam's names.
其中三种在 Python 里叫别的名字——int、float、str—— 所以考试问的时候,要用考纲的说法来回答。
A constant is a value that never changes while the program runs — pi, a tax rate, the number of days in a week.
常量是程序运行期间永远不变的值—— 圆周率、税率、一周的天数。
The exam has a keyword for it.
考卷上有专门的关键字。
Python does not, so the convention is to write it in capitals.
Python 没有,所以约定是把它的名字写成大写。
Be honest about what that means: nothing stops you changing it.
这里要说实话:并没有什么能阻止你去改它。
The capitals are a message to whoever reads the code next, including you in a month.
大写是写给下一个读这段代码的人看的, 包括一个月后的你自己。
Because input hands you text, you will convert constantly, and there are three to know.
因为 input 交给你的是文本,你会不停地做转换,有三个要记住。
Int makes a whole number.
int 得到整数。
Float for a decimal.
float 得到小数。
And str turns a number back into text, which you need when you join it onto a message.
而 str 把数字变回文本,当你要把它拼进一句话时就需要它。
Now the three tasks: an area, a total cost, and a number read in and increased by three.
现在做那三道题: 一个面积,一个总价,还有一个读进来再加 3 的数字。
Four things to take with you.
带走四点。
One: a variable is a named box, filled by assignment.
第一:变量是一个有名字的盒子,通过赋值来填充。
Two: the five types are integer, real, char, string and Boolean.
第二:五种类型是 integer、real、char、string 和 Boolean。
Three: a constant never changes — write its name in capitals.
第三:常量永远不变——它的名字写成大写。
Four: int, float and str convert between types.
第四:int、float 和 str 用来做类型转换。
Now do the three tasks.
现在去做那三道题。