跟读练习: #62 Python Tutorial for Beginners | Generators - 通过视频学习英语口语

选择练习模式

每种模式都会打开全屏练习室。

113 句
如果句子过短或过长,请点击 Edit 进行调整。
1
Welcome back aliens, my name is Davin Reddy and in this video we'll talk about generators.
2
Now in the earlier video we have talked about iterators.
3
So normally we use iterators to print or to fetch one value at a time.
4
So let's say if you have a list of values, let's say 100 values, And if you want one by one value, what makes sense is to use iterator.
5
But there are small issues with iterator right?
6
The first one you need to get the iterator where you have to define those two functions.
7
Next and iter.
8
We don't want to do that.
9
We want Python to do it for us.
10
And that's where Python says, okay, if you want iterators, we will give you generators.
11
Okay, but now you will think we have two different concepts.
12
Not exactly.
13
Generators will give you iterators.
14
Our job is done, right?
15
So generator give you iterator.
16
But how exactly to create a generator?
17
So let's do that.
18
So what I will do is I will just jump to Another file which is gen .py, you can create your own file there.
19
And here let me define a function.
20
That's right, we have to define a function, not a class this time.
21
So let's say our function define and we'll do the same thing, we'll return the top 10 values.
22
So we'll say top 10 and this will return the top 10 value and I will call this as well.
23
So I will let me just say I have values and this will be top 10.
24
So top 10 is.
25
a function which will give you the iterator.
26
But hold on, a function cannot give you the iterator, right?
27
A function has to be something special.
28
So we have to convert this function into a generator.
29
And the way to do that is, Normally in function we write return, right?
30
So if you say return 5, so this values will be having 5.
31
But if you instead of saying return 5, if you say
32
e -gildify your job is done because e -gildify your special keyword which will make your function as a generator.
33
but now you will think what's the difference even return will
34
give you the value even it will also give you the
35
value what i will do is i will just go back here let me just print the value
36
and if you run this code
37
so you can see we got a different thing instead of
38
getting a value 5 we got a object of generator
39
and that's the thing you know because generator gives you an iterator
40
so this function is not a normal function this is a generator because we are using yield yes if you will be different.
41
A will also return the value back it will return in the format of a iterator.
42
And everyone knows if you want to fetch something from an iterator, we have to use the next Let's run this code and you can see we got 5.
43
But now you will think, okay, that's fine.
44
Even return give the same output, right?
45
No, there's a difference.
46
In yield, since it's a generator which will give you iterator, you can write multiple yield statements.
47
So let's say yield 1.
48
Let's copy this.
49
Let's do it for four times and then they will be having different values here 2, 3 and 4.
50
Now you can see we got 4 yield which is 1, 2, 3, 4 and if you run this code, you will only get the first value because you are saying next only once.
51
So this is same as iterator where you are getting multiple values, right?
52
So you got your own iterator without using next and iterator function.
53
Let me just do that one more time.
54
I will say next.
55
Yes, you can also say next and in bracket you can say valves.
56
That's a choice you have.
57
Otherwise, this will work.
58
You can see we got one, two.
59
In fact, we can also use a loop.
60
So let's use a loop.
61
I will say for I in valves.
62
I'll let you print I here.
63
The moment you do that, you can see it will print all the values for you.
64
The remaining values which is three and four.
65
This is how you can create the rate up just by using that one particular keyword which is yield.
66
Okay, now there is another example we can take here.
67
Example, let's say I want to print top 10 perfect square.
68
You can do that.
69
So let's create one.
70
So what I will do is I will just remove this part.
71
Okay, because the logic will change.
72
Everything else will remain same.
73
Let me just not do this.
74
Let's use a for loop to print all the values.
75
But what should be logic?
76
So what I will do is I will say I will take a variable
77
which is i initially or maybe n will do n is equal to 1
78
and now since we want to print all the perfect square we have to use a loop.
79
I will not be using a for loop here because indirectly for uses iterator.
80
Let's use while so I will say while n less than equal to 10
81
because we want to fetch top 10
82
and every time you find a new value you have to just have to say yield.
83
You can say sq is equal to n into n that's how you find a square.
84
Once you got this square you can simply say yield and you can say sq.
85
Okay, so we are sending the value right.
86
So it is almost same as return but then return will terminate the function this will not.
87
That's something you have to remember.
88
Now, once you say sq you have to say n
89
because you have to also iterate your n right you have
90
to say n plus is equal to one i guess our job is done this should work let's try
91
so i will just run this application
92
and you can see we got top 10 perfect square we got 1 4 9 16 25
93
so that's how you can do it
94
because this yield will give you the next next value
95
because see when you say you're running a loop you're fetching one by one value
96
so when you fetch the first value this yield will return one when the loop says hey i value, it will give you nine.
97
So that's how you create a iterator using a generator.
98
But the question is why someone will use a generator?
99
Think about this.
100
Let's say you are fetching 1000 records from a database.
101
So when you say you're fetching 1000 records, maybe you want to print all, or maybe you want to process something from those records.
102
So when you say you want to fetch 1000 records, all these 1000 records will be loaded in your memory.
103
We don't want that.
104
Maybe you want to work with one value at a time.
105
So let's say 1000 records, we want to work with one value at a time.
106
In that case, you can use generator instead of using, instead of fetching the entire list, you can fetch one by one value.
107
So that's something you can do with generator.
108
That's maybe you can call as a real -life example.
109
So this is how we use generator with the help of yield keyword.
110
So I hope you enjoyed this video.
111
Let me know in the comment section and do subscribe for other videos.
112
Bye.
113
you

下载应用

流利口语所需的一切

AI 发音评分逐句打分
音标练习掌握每个音
词汇学习建立你的词库
词汇游戏边玩边学

同频道

FOR YOU

推荐视频

本课的词汇与口语要点

这节 B1 级别的口语课以视频“Python Tutorial for Beginners”为素材。 视频中反复出现的词有:value, iterator, generator, function, return。 这段视频共有 113 个句子、1240 个单词可供跟读。 讲话部分时长为 6:02。 说话人语速较快,每分钟约 206 个词,会出现较多连读和弱读。 86% 的单词属于英语最常用的 3,000 词,其余的词建议在练习前先学一下。

视频中的重点词汇

视频中最难的 11 个单词,附发音和释义:

单词发音释义
generator 名词/ˈdʒɛnəɹeɪtə(ɹ)/發電機 /发电机
yield 动词/jiːld/產量 /产量, 產生 /产生
fetch 动词/fɛt͡ʃ/取
loop 名词/luːp/圈, 環 /环
define 动词/dɪˈfaɪn/界定
keyword 名词/ˈkiː.wɜːd/關鍵詞 /关键词, 關鍵字 /关键字
valve 名词/ˈvælv/閥門 /阀门
terminate 动词/ˈtɝmɪneɪ̯t/結束 /结束, 終止 /终止
bracket 名词/ˈbɹækɪt/支架, 托架
subscribe 动词/səbˈskɹaɪb/簽署 /签署
database 名词/ˈdeɪtəˌbeɪs/數據庫 /数据库

视频中出现的短语动词

单词释义
go back 动词回去, 返回

值得反复跟读的句子

视频中简短而完整的句子,可以直接用在日常对话里:

  • We don't want to do that.
  • That's a choice you have.
  • I'll let you print I here.
  • That's something you have to remember.

视频中的语法

说话人最常用的结构,并附上视频中的原话:

结构视频中的用法
条件句 if + 从句,will/would + 动词 — 条件及其结果if you want iterators, we will give · if you run this code, you will only
定语从句 who / which + 从句 — 补充说明人或事物file which is · function which will · keyword which will

需要注意的发音

说话人用了 10 次缩略和弱读形式,例如 we'll, you're, don't。请按听到的简短形式来说。

  • 长单词——注意重音位置: generator /ˈdʒɛnəɹeɪtə(ɹ)/, indirectly /ˌɪn.dɪˈɹɛk(t).li/

中文母语者容易读错的音:

  • /v/ — 不要读成 /w/,上齿轻触下唇: valve /ˈvælv/, convert /kənˈvɝt/, variable [ˈvæɹ.i.ə.bl̩]
  • 词尾辅音 — 要读清楚,后面不要加元音: yield /jiːld/, fetch /fɛt͡ʃ/, loop /luːp/, keyword /ˈkiː.wɜːd/, valve /ˈvælv/
  • /r/ 和 /l/ 的区别: indirectly /ˌɪn.dɪˈɹɛk(t).li/, variable [ˈvæɹ.i.ə.bl̩]

如何用这段视频练习

  1. 先完整听一遍视频,不要开口,记下不认识的单词。
  2. 先用 0.75 倍速逐句跟读,熟练之后再回到正常速度。
  3. 录下自己的声音并与原声对比,特别注意 generator, yield, fetch 这类单词。

什么是跟读法?

跟读法 (Shadowing) 是一种有科学依据的语言学习技巧,最初开发用于专业口译员的培训,并由多语言者Alexander Arguelles博士普及。这个方法简单而强大:您在听英语母语原声的同时立即大声重复——就像是一个延迟1-2秒紧跟说话者的影子。与被动听力或语法练习不同,跟读法强迫您的大脑和口腔肌肉同时处理并模仿真实的讲话模式。研究表明它能显着提高发音准确性,语调,节奏,连读,听力理解和口语流利度——使其成为雅思口语备考和真实英语交流最有效的方法之一。

影子跟读法: 阅读完整分步指南 →