栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python的类和函数

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python的类和函数

最近需要用python,居然有点忘了类和函数怎么定义了,所以记录一下

def f(a,b):
    return a,b,a+b

'''
s=f(1,2)#小括号表示元组
lst=[]

for i in s:
    lst.append(i)

print(lst)
'''

class book:
    count=0
    def __init__(self,number,salary):
        self.number=number
        self.salary=salary
        print("欢迎进入")
        book.count+=1
    def show(self):
        print("数目:"+str(self.number)+" 价格:"+str(self.salary))
        print("第"+str(book.count)+"位用户")

lst=[]
def show():
    print("1 增加用户")
    print("2 显示数据")
    print("3 退出程序")


count=0
def fun():
    print("一共有"+str(count)+"个人")
    a=int(input("请输入查找谁的数据"))
    lst[a-1].show()
      
while(1):
    show()
    a=int(input("请输入数字"))
    if(a==1):
        salary=input("请输入数量")
        number=input("请输入价格")
        lst.append(book(salary,number))
        count+=1
    elif(a==2):
        fun()
    elif(a==3):
        break
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/715364.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号