金鸡湖竞赛杂记1-理论

class gradapa(object):
    def __init__(self, money):
        self.money = money
        print("gradapa money:",money)

    def p(self):
        print("this is gradapa")


class father(gradapa):
    def __init__(self, money, job):
        super().__init__(money*3)
        self.job = job
        print("father money:", money)
        print("father job:",self.job)

    def p(self):
        print("this is father,我重写了父类的方法")


class mother(gradapa):
    def __init__(self, money, job):
        super().__init__(money*2)
        self.job = job
        print("mother money:", money)
        print("mother job:",self.job)


    def p(self):
        print("this is mother,我重写了父类的方法")
        return 100


# 定义一个函数,函数调用类中的p()方法
def fc(obj):
    obj.p()


gradapa1 = gradapa(9000)

father1 = father(5000, "工人")
mother1 = mother(1000, "老师")

fc(gradapa1)  # 这里的多态性体现是向同一个函数,传递不同参数后,可以实现不同功能.

fc(father1)

fc(mother1)

print(fc(mother1))

# == =运行结果: == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
# gradapa money: 9000
# gradapa money: 15000
# father money: 5000
# father job: 工人
# gradapa money: 2000
# mother money: 1000
# mother job: 老师
# this is gradapa
# this is father,我重写了父类的方法
# this is mother,我重写了父类的方法
# this is mother,我重写了父类的方法
# None

参考1

class A():
    def __init__(self):
        print('init A...')
        print('end A...')


class B(A):
    def __init__(self):
        print('init B...')
        A.__init__(self)
        print('end B...')


class C(A):
    def __init__(self):
        print('init C...')
        A.__init__(self)
        print('end C...')


class D(B, C):
    def __init__(self):
        print('init D...')
        B.__init__(self)
        C.__init__(self)
        print('end D...')


if __name__ == '__main__':
    D()

# ''' ------ Output ------
# init D...
# init B...
# init A...
# end A...
# end B...
# init C...
# init A...
# end A...
# end C...
# end D...
# '''

参考2

a_list=[1,2,3]
b_list=['one','two','three']


result=zip(a_list,b_list)

print(set(result))
print(list(result))
#运行结果
#{(2, 'two'), (1, 'one'), (3, 'three')}
#[]

在这里插入图片描述

print([1,2,3]*3)
#运行结果
#[1, 2, 3, 1, 2, 3, 1, 2, 3]

==优先级大于=

x=3 == 5,888,555,9999
print(x)
#运行结果
#(False, 888, 555, 9999)

在这里插入图片描述

x=3
print("id1:",id(x))
x+=6
print("now id:",id(x))
print()
def add(n):
    return lambda x:x+n
f=add(1)
print(f(2))
#运行结果
#3
strs=' I like python '
one=strs.split(' ')
two=strs.split()
print(one)
print(two)

在这里插入图片描述

strs=' I like python '
one=strs.split(' ')
two=strs.split()
print(one)
print(two)


s= 'www.dod.com.cn'
# 默认分隔符
print(s.split())
#  . 分割
print(s.split('.'))
#  分割一次   2次
print(s.split('.',1))
print(s.split('.',2))
# 取出被 . 分割的下标为1的字符串
print(s.split('.',2)[1])
# 分割最多次实际与不加参数一样(默认分割富一样)
print(s.split('.',-1))
#分割三次并将分割的字符串保存到三个文件内
s1,s2,s3= s.split('.',2)
print(s1)
print(s3)
print(s2)

# 去掉换行符  \n  \t
c = '''hello
    world'''
print(c)
print(c.split('\n'))
print(c.split('\t'))

# 分离文件名和路径
#os.path.split():按照路径将文件名和路径分割开
import  os
print(os.path.split('/dodo/soft/python/'))
print(os.path.split('/dodo/soft/python'))

#超级实例列举

a= 'hello boy<[www.dodo.com.cn]>byebye'
# 已[分割
print(a.split('['))
# 以【分割后取值下标为1的值,然后再次已】分割取下标为0的值
print(a.split('[')[1].split(']')[0])
# 以【分割后取值下标为1的值,然后再次以】分割取下标为0的值在次以。分割
print(a.split('[')[1].split(']')[0].split('.'))

在这里插入图片描述

x={i:str(i+3)for i in range(2)}
print(x)
print(sum(x))

在这里插入图片描述

# [index for index,value in enumerate([3,5,7,3,7])]if value==max([3,5,7,3,7])
# enumerate多用于在for循环中得到计数
a = ['a', 'c', 'd', 'ok']
for index, item in enumerate(a):
    print(index, item)  # index,索引号;item列表中的元素项如a,c ,d

在这里插入图片描述

list1 = [1,2,4,"hello","xy","你好"]
a = list1.pop()#默认弹出最后一个元素
print(a,list1)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值