Its name is malloc for memory allocation and what malloc does for us is we say, hmm, the user has typed in a three-letter word.
它为我们分配内存地址,它为用户输入的3个字母单词,分配地址。
That is the address in memory in the heap of the first byte that the user typed in.
那是用户输入的字符串第一个字节,内存中堆的地址。
And to do this, I'm going to use some code that I've already typed in.
为了达到这个目的,我会去使用一些,我已经写好的代码。
Let's assume that the user typed in a pretty short word we didn't run out of memory or anything crazy so here's the new feature.
假设用户输入,很短的单词,没有出现超出内存之类的问题,这里是新的特点。
In this case, I'm going to get back the answer 3 F-O-O because the user typed in F-O-O, but wait a minute, what's with this?
假若这样,我得到了答案3,因为用户输入了,等一下,用这个干吗?
Which is, and we're going to do some examples of this, initially we just typed in expressions Python into the interpreter; that is,directly into Python And as I suggested last time, the interpreter is actually a program inside of the machine that is basically following the rules we're describing here to deduce the value and print it up.
也就是,我们将会对这一点讲解一些例子,一开始我们只是简单的把表达式输入,到解释器里面去,也就是直接传给,我上次跟大家讲过,解释器实际上是,机器内置的,按照我们描述的规则,来推算出结果值并把值显示出来的一个东西。
Well, get string again is returning the address of the string the user typed in, D the address of the very first character like the letter D and storing that address in this variable s1.
好的,GetString返回的是,用户输入的字符串的地址,第一个字符的地址,比如字母,然后把这个地址存储在这个变量s1中。
s2 So, I'm passing in the first character in s2, I'm making it uppercase and then I'm putting it back so casually speaking this is just capitalizing the first letter of whatever word the user typed in to s2.
那么,我把第一个字符传递给,我把它转换成大写的,然后存下来,简单说,这就是把用户输入s2中的单词,的第一个字母转换成大写的。
I store in s1 the address of the first byte that the user typed in and by the way that first bite happens to live in this new place called the heap and that's the only update to the story thus far.
我在s1中存储的是用户输入的字符串的首地址,这样第一个字节存储在这块,新的堆的地方,这个是唯一的修正。
So Arg V bracket I, gives me the Ife string that I typed in.
那么Argv,把我刚键入的字符串Ife传给我。
And if you've typed in l when you should've 1 typed a 1, or a 1 when you should've typed an l, you're likely to miss it. If you've made a mistake with upper and lower case. Things like that. So just be very careful looking at that.
如果你本来想打,1,的时候,却输成了,l,或者打,l,的时候输成了,你很可能注意不到这个错误,如果你把大小写弄混了也是一样,要注意这个错误。
-- Else if n is greater than 4 and n is less than 6 -- 7 let's call it medium -- else if n is greater than or equal to 7, -- less than or equal to 10 -- let's call it "big" -- and if the user typed in zero or negative 10 or 20 or whatever, let's just use the all-inclusive else block and just say, "You picked an invalid number."
否则如果n大于4,并且n小于-,我们叫它为中间数--否则如果n大于等于,小于等于10--我们叫它为“大数“,如果用户键入了0或者-10或20或其它的,让我们用一个广泛的else子句,只需要说,“你选了一个非法的数字“
But the string, the sentence or the words that we're displaying on the screen, previously you clicked on a little white text field and typed it in, well now you're gonna do the same thing at the keyboard but you're gonna have to sandwich it in between double quotation marks.
这些你想输出到屏幕上的字符串啊,语句啊,单词啊,或者你事先,在白色输入框中敲进去的内容,现在你们需要用键盘做同样的事情,但是你们要写在,双引号之间。
And notice, by the way, when I typed it how print showed up in a different color?
注意,顺便说一下,当我输入的时候,怎样才能显示不同的颜色呢?
All the supreme court justices would share our social values. And most importantly, our programs would work the first time we typed them. By now you may have noticed that we do not live in an ideal world.
符合我们的社会价值观,但是最重要的是,我们写好的程序,第一次就能顺利运行,如今你可能已经注意到了,我们生活的并不是一个理想的世界。
s1 We're assigning to s1 the string that the user typed in.
我们把用户输入的字符串赋值给。
This is what you typed into the white box in Scratch and anyone perhaps already familiar, the backslash N is the shorthand way of saying what?
这也是你们在Scratch的白色输入框里要填入的东西,也许已经有人知道,反斜杠n代表某种简写方式吧?
So STR, which I just typed up there, takes in parens, some input, and it converts it into a string, so that now I can use that John where I was expecting a string. John.
因此STR,也就是,我刚刚输入的,然后把这个输入变更为一个字符串,因此现在我就能,在需要用字符串的地方使用这个对象了。
I love Lisp, but Lisp is certainly in the category of a very weakly typed language.
我爱Lisp,但是Lisp当然,是属于在类型检查比较弱的语言一类。
F-O-O in lowercase and, in fact, foo it is buggy because I typed lowercase F-O-O and FOO yet I get back capital F-O-O as both the original and the copy and that's simply because I haven't done this correctly.
小写的f-o-o,实际上,它是有bug的,因为我输入小写的,而我得到的原始的和拷贝的都是大写的,简单说,我处理错了。
应用推荐