课程: Python: Design Patterns (2021)
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Iterator example
- [Instructor] Now, let's define our iterator. We start with creating a list. The list contains German words counting up to five. Here, we'll use Python's built-in iterator. The iterator will create tuples consisting of pairs of numbers and equivalent German words. For example, one and the German word, eins. The tuple here means a pair. One and eins that's a tuple. Two and zwei. That's another tuple. The built-in iterator provided by Python is zip. We have to generate numbers up to five. So we use the function range here. So type range. The argument of the function is the number of German words to display, which is count. So type count. This is the first argument of the zip iterator. The second argument is the list itself. The numbers in German is our list. Type numbers in German. The range function here is important, because it allows us to know up to what number we can count. We use a variable called iterator…
内容
-
-
-
-
-
-
(已锁定)
Observer1 分钟 5 秒
-
(已锁定)
Observer example6 分钟 22 秒
-
(已锁定)
Visitor56 秒
-
(已锁定)
Visitor example6 分钟 42 秒
-
(已锁定)
Iterator1 分钟 15 秒
-
(已锁定)
Iterator example4 分钟 32 秒
-
(已锁定)
Strategy40 秒
-
(已锁定)
Strategy example5 分钟 44 秒
-
(已锁定)
Chain of responsibility1 分钟 4 秒
-
(已锁定)
Chain of responsibility example5 分钟 57 秒
-
(已锁定)
-
-