@@ -246,6 +246,25 @@ while True:
246
246
print (thing)
247
247
```
248
248
249
+ ## Checking if object is iterable or not
250
+
251
+ There is an easy way of checking if an object in python is iterable or not. The following code will do the needful.
252
+ ``` python
253
+ >> > def check (A ):
254
+ ... try :
255
+ ... st = iter (A)
256
+ ... print (' yes' )
257
+ ... except TypeError :
258
+ ... print (' no' )
259
+ ...
260
+ >> > check(25 )
261
+ no
262
+ >> > check([25 ,35 ])
263
+ yes
264
+ >> >
265
+ ```
266
+ Here you can observe that the 25 is an integer, so it is not iterable, but [ 25,35] is a list which is iterable so it outputs no and yes respectively.
267
+
249
268
## Generators
250
269
251
270
It's possible to create a custom iterator with a class that defines an
@@ -442,7 +461,6 @@ does the same thing as our `count()`.
442
461
generator runs it to the next yield and gives us the value it yielded.
443
462
- [ The itertools module] ( https://docs.python.org/3/library/itertools.html )
444
463
contains many useful iterator-related things.
445
-
446
464
***
447
465
448
466
If you have trouble with this tutorial please [ tell me about
0 commit comments