使用class在Python中编写程序 [英] Write a program in Python using class
本文介绍了使用class在Python中编写程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用存储员工详细信息的类在python中编写程序,询问用户要存储多少员工数据我是如何创建n个对象的
我的尝试:
班级员工:
def __init __(自我,姓名,年龄,薪水):
self.name = name
self.age = age
self.salary = salary
n = int(raw_input(你必须输入多少员工详细信息)
for i in range(1,n):
emp [i] =员工
#这里给出错误
解决方案
你需要声明emp
作为集合或列表类型,然后才能使用下标。请参阅 5.数据结构 - Python 3.4.8文档 [ ^ ]。
Write a program in python using class that stores employee details by asking user how many employee data to be stored i am stucked in how to create n number of object
What I have tried:
class Employee:
def __init__(self,name,age,salary):
self.name = name
self.age= age
self.salary = salary
n = int(raw_input("how many employee details you have to enter ")
for i in range(1,n):
emp[i]= Employee
# here it gives error解决方案You need to declareemp
as a collection or list type, before you can use subscripts on it. See 5. Data Structures — Python 3.4.8 documentation[^].
这篇关于使用class在Python中编写程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文