# -*- coding: UTF-8 -*-
# 作者:huanhuilong
# 标题:Python 元组推导式 # 描述:Python 独步天下的推导式表达式,使用元表推式过滤长度小于等于4的书籍 def test(): books = ('程序员修炼之道', '构建之法', '代码大全', 'TCP/IP协议详解') reading = (book for book in books if len(book) <= 4) print("太长的书就不看了,只读短的:") for book in reading: print(" ->《{}》".format(book)) print("可是发现书的名字短,内容也可能很长啊!") if __name__ == '__main__': test()