'''
@Author: your name
@Date: 2020-07-27 17:50:16
@LastEditTime: 2020-07-27 22:27:19
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: \vscode_py\day21.py
'''
# Question 85
# By using list comprehension, please write a program to print the list after removing the 0th,4th,5th numbers in [12,24,35,70,88,120,155].
def Q85():
li = [12,24,35,70,88,120,155]
lo=[li[i] for i in range(len(li)) if i not in [0,4,5]]
print(lo)
# Question 86
def Q86():
li = [12,24,35,70,88,120,155]
lo=[i for i in li if i!=24]
print(lo)
# Question 87
# 找到交叉的元素
# Use set() and "&=" to do set intersection operation.
def Q87():
list1 = [1,3,6,78,35,55]
list2 = [12,24,35,24,88,120,155]
ans=set(list1) & set(list2)
print(ans)
# Question 88
# 去掉list中重复的元素
def Q88(li):
seen=set()
for i in li:
if i not in seen:
seen.add(i)
print(list(seen))
# # Question 89
# # Define a class Person and its two child classes: Male and Female. All classes have a method "getGender" which can print "Male" for Male class and "Female" for Female class.
# class Person:
# def getGender(self):
# print("Unknow")
# class Male(Person):
# def getGender(self):
# print("Male")
# class Female(Person):
# def getGender(self):
# print("Female")
# Question 89方法2
class Person:
def __init__(self):
= "unknown"
def getGender(self):
print()
class Male(Person):
def __init__(self):
= "male"
class Female(Person):
def __init__(self):
= "female"
if __name__ == "__main__":
# Q85()
# Q86()
# Q87()
# li=[12,24,35,24,88,120,155,88,120,155]
# Q88(li)
p=Person()
p.getGender()
boy=Male()
boy.getGender()
girl=Female()
girl.getGender()