1
Define a class named Circle which can be constructed by a radius. The Circle class has a method which can compute the area.
分析:考察构造函数和类方法
1 | class Circle(object): |
2
Define a class named American and its subclass NewYorker.
1 | class American(object): |
3
Define a class named American which has a static method called printNationality.
1 | class American(object): |
4
Write a program which can map() to make a list whose elements are square of numbers between 1 and 20 (both included).
分析:lambda函数的用法
1 | s = map(lambda x: x**2, range(1,21)) |
5
Write a program which can filter() to make a list whose elements are even number between 1 and 20 (both included).
1 | l = filter(lambda x: x%2==0,range(1,21)) |
6
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].
1 | li = [1,2,3,4,5,6,7,8,9,10] |
7
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].
1 | li = [1,2,3,4,5,6,7,8,9,10] |
8
Write a program which can filter even numbers in a list by using filter function. The list is: [1,2,3,4,5,6,7,8,9,10].
1 | li = [1,2,3,4,5,6,7,8,9,10] |
9
Write a program which accepts a string as input to print “Yes” if the string is “yes” or “YES” or “Yes”, otherwise print “No”.
1 | s =input("Please input:") |
10
Write a program to generate and print another tuple whose values are even numbers in the given tuple (1,2,3,4,5,6,7,8,9,10).
分析:考察元组
1 | t =(1,2,3,4,5,6,7,8,9,10) |
11
With a given tuple (1,2,3,4,5,6,7,8,9,10), write a program to print the first half values in one line and the last half values in one line.
分析:[a : b : c]表示从a到b步长为c取元素
1 | tp=(1,2,3,4,5,6,7,8,9,10) |
12
Define a function which can generate and print a tuple where the value are square of numbers between 1 and 20 (both included).
分析:考察元组
1 | def printTuple(): |
13
Define a function which can generate a list where the values are square of numbers between 1 and 20 (both included). Then the function needs to print all values except the first 5 elements in the list.
1 | def printList(): |
14
Define a function which can generate a list where the values are square of numbers between 1 and 20 (both included). Then the function needs to print the last 5 elements in the list.
分析:考察列表
1 | def printList(): |
15
Define a function which can generate a list where the values are square of numbers between 1 and 20 (both included). Then the function needs to print the first 5 elements in the list.
1 | def printList(): |
16
Define a function which can generate and print a list where the values are square of numbers between 1 and 20 (both included).
1 | def printList(): |
17
Define a function which can generate a dictionary where the keys are numbers between 1 and 20 (both included) and the values are square of keys. The function should just print the keys only.
分析:考察字典
1 | def printDict(): |
18
Define a function which can generate a dictionary where the keys are numbers between 1 and 20 (both included) and the values are square of keys. The function should just print the values only.
1 | def printDict(): |
19
Define a function which can print a dictionary where the keys are numbers between 1 and 20 (both included) and the values are square of keys.
1 | def printDict(): |
20
Define a function which can print a dictionary where the keys are numbers between 1 and 3 (both included) and the values are square of keys.
1 | def printDict(): |
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论