Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generate list in class
#1
Is it possible to generate a list with the inputs in my function addperson, which I can print then with my function printperson? I'm a bit confused with that assignment at the moment. Thanks a lot!

class person:
    def __init__(self, name, id, age):
        self.name = name
        self.id = id
        self.age = age

    def addperson(self):
        name = input("Please enter name:")
        id = id(name)
        age = input("Please enter age:")
        #list with name, id and age should be generated 

    def printperson(self):
        print(self.id, self.name, self.age)
Reply


Messages In This Thread
Generate list in class - by P13N - Dec-26-2018, 10:09 PM
RE: Generate list in class - by stullis - Dec-26-2018, 10:18 PM
RE: Generate list in class - by P13N - Dec-27-2018, 05:46 AM
RE: Generate list in class - by stullis - Dec-27-2018, 10:06 AM
RE: Generate list in class - by P13N - Dec-27-2018, 11:24 AM
RE: Generate list in class - by stullis - Dec-27-2018, 07:01 PM
RE: Generate list in class - by woooee - Dec-28-2018, 01:26 AM
RE: Generate list in class - by P13N - Dec-28-2018, 10:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to read module/class from list of strings? popular_dog 1 467 Oct-04-2023, 03:08 PM
Last Post: deanhystad
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,917 Oct-03-2021, 05:16 PM
Last Post: Yoriz
  Generate a list sasitha96 5 2,345 Sep-20-2021, 07:03 PM
Last Post: sasitha96
  apendng to a list within a class gr3yali3n 4 2,335 Feb-16-2021, 06:30 AM
Last Post: buran
  How to append multiple <class 'str'> into a single List ahmedwaqas92 2 2,312 Jan-07-2021, 08:17 AM
Last Post: ahmedwaqas92
  How to generate a log in a list style? wagnergt12 5 2,739 Apr-22-2020, 12:47 PM
Last Post: buran
  extract first and last 5 elements from given list and generate a new list. Raj_Kumar 1 2,370 Dec-07-2019, 05:03 PM
Last Post: ichabod801
  I created a function that generate a list but the list is empty in a new .py file mrhopeedu 2 2,291 Oct-12-2019, 08:02 PM
Last Post: mrhopeedu
  Appending a list in a class from a callback function snizbatch 5 3,709 Sep-01-2019, 06:27 AM
Last Post: snizbatch
  how to add class instance attributes from list 999masks 2 2,699 Jul-22-2019, 07:59 AM
Last Post: 999masks

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020