首页 > 编程语言 > 详细

Python全栈__迭代器、生成器、知识点补充、列表推导式,生成器表达式、如何系统科学的学习Python

时间:2018-06-02 13:23:33      阅读:224      评论:0      收藏:0      [点我收藏+]

1、迭代器

   (1)可迭代对象

技术分享图片
1 s1 = 123
2 for i in s1:
3     print(i)
可迭代对象

   示例结果:

技术分享图片
D:\Python36\python.exe "E:/Python/课堂视频/day13视频与课堂笔记/day13课堂笔记/day13/02 迭代器.py"
1
2
3
True
False

Process finished with exit code 0
示例结果

 

  int object is not iterable

技术分享图片
1 for i in 123:
2     print(i)
Int object is not iterable

示例结果:

技术分享图片
D:\Python36\python.exe "E:/Python/课堂视频/day13视频与课堂笔记/day13课堂笔记/day13/02 迭代器.py"
Traceback (most recent call last):
  File "E:/Python/课堂视频/day13视频与课堂笔记/day13课堂笔记/day13/02 迭代器.py", line 8, in <module>
    for i in 123:
TypeError: int object is not iterable

Process finished with exit code 1
示例结果

 

  内部含有__iter__方法的就是可迭代对象,遵循可迭代协议。

 

技术分享图片
1 dir
2 print(dir(123))  # ‘__iter__‘
可迭代对象的判断

 

 

 

   结果:

技术分享图片
1 D:\Python36\python.exe "E:/Python/课堂视频/day13视频与课堂笔记/day13课堂笔记/day13/02 迭代器.py"
2 [__add__, __class__, __contains__, __delattr__, __dir__, __doc__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __getnewargs__, __gt__, __hash__, __init__, __init_subclass__, __iter__, __le__, __len__, __lt__, __mod__, __mul__, __ne__, __new__, __reduce__, __reduce_ex__, __repr__, __rmod__, __rmul__, __setattr__, __sizeof__, __str__, __subclasshook__, capitalize, casefold, center, count, encode, endswith, expandtabs, find, format, format_map, index, isalnum, isalpha, isdecimal, isdigit, isidentifier, islower, isnumeric, isprintable, isspace, istitle, isupper, join, ljust, lower, lstrip, maketrans, partition, replace, rfind, rindex, rjust, rpartition, rsplit, rstrip, split, splitlines, startswith, strip, swapcase, title, translate, upper, zfill]
3 
4 Process finished with exit code 0
示例结果

 

技术分享图片
D:\Python36\python.exe "E:/Python/课堂视频/day13视频与课堂笔记/day13课堂笔记/day13/02 迭代器.py"
[__add__, __class__, __contains__, __delattr__, __dir__, __doc__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __getnewargs__, __gt__, __hash__, __init__, __init_subclass__, __iter__, __le__, __len__, __lt__, __mod__, __mul__, __ne__, __new__, __reduce__, __reduce_ex__, __repr__, __rmod__, __rmul__, __setattr__, __sizeof__, __str__, __subclasshook__, capitalize, casefold, center, count, encode, endswith, expandtabs, find, format, format_map, index, isalnum, isalpha, isdecimal, isdigit, isidentifier, islower, isnumeric, isprintable, isspace, istitle, isupper, join, ljust, lower, lstrip, maketrans, partition, replace, rfind, rindex, rjust, rpartition, rsplit, rstrip, split, splitlines, startswith, strip, swapcase, title, translate, upper, zfill]

Process finished with exit code 0
View Code

 

 

2、生成器

 

 

 

3、知识点补充

 

 

 

4、列表推导式,生成器表达式

 

 

 

5、如何系统科学的学习Python

 

Python全栈__迭代器、生成器、知识点补充、列表推导式,生成器表达式、如何系统科学的学习Python

原文:https://www.cnblogs.com/ZN-225/p/9125049.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!