美文网首页
Python-41~45

Python-41~45

作者: AoEliauk | 来源:发表于2020-10-22 15:33 被阅读0次

    ---41---

    Question:

    >Write a program which can map() to make a list whose elements are square of elements in [1,2,3,4,5,6,7,8,9,10].

    Hints:

    >Use map() to generate a list.Use lambda to define anonymous functions.

    Solution:


    ---42---

    Question:

    >Write a program which can map() and filter() to make a list whose elements are square of even number in [1,2,3,4,5,6,7,8,9,10].

    Hints:

    >Use map() to generate a list.Use filter() to filter elements of a list.Use lambda to define anonymous functions.

    Solution:

    解法一

    解法二


    ---43---

    Question:

    >Write a program which can filter() to make a list whose elements are even number between 1 and 20 (both included).

    Hints:

    >Use filter() to filter elements of a list.Use lambda to define anonymous functions.

    Solution:

    解法一

    解法二


    ---44---

    Question:

    >Write a program which can map() to make a list whose elements are square of numbers between 1 and 20 (both included).

    Hints:

    >Use map() to generate a list. Use lambda to define anonymous functions.

    Solution:

    解法一

    解法二


    ---45---

    Question:

    >Define a class named American which has a static method called printNationality.

    Hints:

    >Use @staticmethod decorator to defineclass static method.

    Solution:


    Python filter() 函数 | 菜鸟教程

    Python filter() 函数 | 菜鸟教程

    相关文章

      网友评论

          本文标题:Python-41~45

          本文链接:https://www.haomeiwen.com/subject/yrjsmktx.html