Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3936efb

Browse files
author
Amogh Singhal
authored
Update Python_Programming_Quiz.md
1 parent 6a71298 commit 3936efb

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

‎Python_Programming_Quiz.md‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ If the passed iterators have different lengths, the iterator with the least item
164164

165165
zip can also work with **lists**
166166

167+
__Syntax:__ `zip(iterator1, iterator2, iterator3 ...) -> zip object`
168+
167169
```
168170
a = ("John", "Charles", "Mike")
169171
b = ("Jenny", "Christy", "Monica", "Vicky")
@@ -176,3 +178,53 @@ print(tuple(x))
176178
# prints (('John', 'Jenny'), ('Charles', 'Christy'), ('Mike', 'Monica'))
177179
178180
```
181+
#### 11. Given the first and last names of all employees in your firm, what data type will you use to store it?
182+
183+
#### 12.What does the function `range()` do? <br>
184+
The range() function is used to generate a sequence of numbers over time. <br>
185+
At its simplest, it accepts an integer and returns a `range` object (a type of iterable) <br>
186+
187+
__Syntax:__ `range([start,] stop [, step]) -> range object`
188+
189+
Paramter | Description |
190+
--- | --- |
191+
`start`(optional) | Starting point of the sequence. It defaults to 0. |
192+
`stop` (required) | Endpoint of the sequence. This item will not be included in the sequence. |
193+
`step` (optional) | Step size of the sequence. It defaults to `1`.|
194+
195+
```
196+
>>>
197+
>>> range(5, 10)
198+
range(5, 10)
199+
>>>
200+
>>> list(range(5, 10))
201+
[5, 6, 7, 8, 9]
202+
>>>
203+
```
204+
205+
When `range()` is called with a single argument it generates a sequence of numbers from `0` upto the argument specified __(but not including it)__. That's why the number `5` is not included in the sequence.
206+
207+
Here the `range()` function is called with a `step` argument of `3`, so it will return __every third element__ from `1` to `20` (off course not including 20).
208+
209+
```
210+
>>>
211+
>>> range(1, 20, 3)
212+
range(1, 20, 3)
213+
>>>
214+
>>>
215+
>>> list(range(1, 20, 3))
216+
[1, 4, 7, 10, 13, 16, 19]
217+
>>>
218+
```
219+
220+
You can also use the step argument to count backwards. `step` becomes a negative number in that case
221+
222+
```
223+
>>>
224+
>>> list(range(20, 10, -1))
225+
[20, 19, 18, 17, 16, 15, 14, 13, 12, 11]
226+
>>>
227+
>>> list(range(20, 10, -5))
228+
[20, 15]
229+
>>>
230+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /