【Python Practice】Day 21 Question 85-89

'''
@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):
        self.name = "unknown"
    def getGender(self):
        print(self.name)
class Male(Person):
    def __init__(self):
        self.name = "male"
class Female(Person):
    def __init__(self):
        self.name = "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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tech沉思录

点赞加投币,感谢您的资瓷~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值