一套Python面试题

问题一:

#调用foo函数传入1

#调用class_foo传入1

#调用static_foo传入1

class A(object):
    def foo(self,x):
        print('executing foo(%s%s)'%(self,x))

    @classmethod
    def class_foo(cls,x):
        print('executing foo(%s%s)' % (cls, x))

    @staticmethod
    def static_foo(x):
         print('executing foo(%s)' % x)

a = A()

a.foo(1)
a.class_foo(1)
a.static_foo(1)
问题二:

一个函数用于替换某个字符串的一个或几个字串

def replcestr(replaced_str,new_str):
    after_str = pstr.replace(replaced_str,new_str)
    print(after_str)

pstr = input('请输入源字符串')

replaced_str = input("请输入被替换的字符串")
new_str = input('请输入新选的字符串')
replcestr(replaced_str,new_str)
请输入源字符串world ha ha
请输入被替换的字符串ha ha
请输入新选的字符串wwwww
world wwwww
问题三:

用python使list  [1,2,3,...100]变为 [[1,2,3],[4,5,6]....]

a = [[x,y,z] for x in range(1,98,) for y in range(2,99)for z  in range(3,100)if y-x ==1 if z-y==1 ]

b = [x for x in range(1,101)]
c = [[m,n,l]  for m in b for n  in b for l  in b if n-m ==1 if l-n==1]
print(c)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值