diff --git a/README.md b/README.md index ab5ed9e5272ff05f9b49bc01c822009229152949..ca39b42693ffdecee67b71d5832843458d8b1e96 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Python 技能树开放编辑仓库 ## 初始化 ``` -pip install -r requirement.txt +pip install -r requirements.txt ``` ## 目录结构说明 @@ -262,13 +262,23 @@ int main(int argc, char** argv){ 输出 "Hello,World!" 字符串,找出错的那项。 +## template + +```python +# this part is used to be displayed in jupyter notebook +if ___name__ == '__main__': + str1 = "Hello," + str2 = "World!" + print('str1' + 'str2') +``` + ## 答案 ```python if __name__ == '__main__': str1 = "Hello," str2 = "World!" - print('str1'+'str2') + print('str1' + 'str2') ``` ## 选项 diff --git "a/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/config.json" "b/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/config.json" index 881e1e9af7386aefe6881ce3a726a0190248cd11..a7f4e0c1798c6770273b6dc134b87751460219b9 100644 --- "a/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/config.json" +++ "b/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/config.json" @@ -2,10 +2,10 @@ "export": [ "list01.json", "list02.json", - "tuple.json", + "iter.json", "dict.json" ], "keywords": [], "children": [], "node_id": "python-3-17" -} \ No newline at end of file +} diff --git "a/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/iter.json" "b/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/iter.json" new file mode 100644 index 0000000000000000000000000000000000000000..5de60bd19fd20c694c540f3131f860627a74df6b --- /dev/null +++ "b/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/iter.json" @@ -0,0 +1,7 @@ +{ + "author": "HansBug", + "source": "iter.md", + "depends": [], + "exercise_id": 190, + "type": "code_options" +} diff --git "a/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/iter.md" "b/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/iter.md" new file mode 100644 index 0000000000000000000000000000000000000000..6996cbcd7dd853fb1978c544ef64b2f61796029e --- /dev/null +++ "b/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/iter.md" @@ -0,0 +1,80 @@ +# Python 生成器推导式 + +Python 独步天下的推导式表达式,使用元表推式过滤长度小于等于4的书籍 + +```python +def test(): + books = ('程序员修炼之道', '构建之法', '代码大全', 'TCP/IP协议详解') + + # TODO(you): 此处请为reading进行正确的赋值 + + print("太长的书就不看了,只读短的:") + for book in reading: + print(" ->《{}》".format(book)) + + print("可是发现书的名字短,内容也可能很长啊!") + + +if __name__ == '__main__': + test() +``` + +请选出下列能**正确**实现这一功能的选项。 + + + +## template + +```python +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() +``` + + + +## 答案 + +```python +reading = (book for book in books if len(book) <= 4) +``` + + + +## 选项 + +### A + +```python +reading = (books[i] for book in books: if len(book) < 4) +``` + +### B + +```python +reading = (book for book in books if len(book) < 4) +``` + +### C + +```python +reading = (book for book in books: if len(book) <= 4) +``` + + + + + + + diff --git "a/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/tuple.json" "b/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/tuple.json" deleted file mode 100644 index fcd1a9a7257e3414b8a200f3b598c312c09ee34a..0000000000000000000000000000000000000000 --- "a/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/tuple.json" +++ /dev/null @@ -1,17 +0,0 @@ -{ - "one_line": { - "if len(book) <= 4": [ - "if len(book) < 4" - ], - "for book in books": [ - "for book in books:" - ], - "book for book": [ - "books[i] for book" - ] - }, - "source": "tuple.py", - "depends": [], - "exercise_id": 194, - "type": "code_options" -} \ No newline at end of file diff --git "a/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/tuple.py" "b/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/tuple.py" deleted file mode 100644 index ad9d6d7fbe4885f4e78382de85314173425854e7..0000000000000000000000000000000000000000 --- "a/data/1.python\345\210\235\351\230\266/3.\350\277\233\351\230\266\350\257\255\346\263\225/1.\345\210\227\350\241\250\346\216\250\345\257\274\345\274\217/tuple.py" +++ /dev/null @@ -1,20 +0,0 @@ -# -*- 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()