python将对象放入列表后怎么使用,使用循环将对象添加到列表(python)

我正在尝试使用while循环将对象添加到列表中.

这基本上是我想做的:

class x:

pass

choice = raw_input(pick what you want to do)

while(choice!=0):

if(choice==1):

Enter in info for the class:

append object to list (A)

if(choice==2):

print out length of list(A)

if(choice==0):

break

((((other options))))

我可以将对象添加到列表中,但是我坚持如何在循环中的列表中添加多个对象.

以下是我到目前为止的代码:

print "Welcome to the Student Management Program"

class Student:

def __init__ (self, name, age, gender, favclass):

self.name = name

self.age = age

self.gender = gender

self.fac = favclass

choice = int(raw_input("Make a Choice: " ))

while (choice !=0):

if (choice==1):

print("STUDENT")

namer = raw_input("Enter Name: ")

ager = raw_input("Enter Age: ")

sexer = raw_input("Enter Sex: ")

faver = raw_input("Enter Fav: ")

elif(choice==2):

print "TESTING LINE"

elif(choice==3):

print(len(a))

guess=int(raw_input("Make a Choice: "))

s = Student(namer, ager, sexer, faver)

a =[];

a.append(s)

raw_input("Press enter to exit")

任何帮助将不胜感激!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值