Python Forum
lists Name Address Phone - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: lists Name Address Phone (/thread-27772.html)



lists Name Address Phone - Heyjoe - Jun-21-2020

Hello all,

I reviewed a couple online courses in Python and wrote a few short programs. So I am very new to Python

As far as lists know. I know how to make a list of names. How would I make a list with a person's name, address and phone number?


RE: lists Name Address Phone - menator01 - Jun-21-2020

Maybe not the best example

mylist = [['John Doe', 'some street address', '123 456 7890'],['Jane Doe','another street address','987 555 1234']]

for name, address, phone in mylist:
    print(f'Name: {name} Address: {address} Phone: {phone}')
Output:
Name: John Doe Address: some street address Phone: 123 456 7890 Name: Jane Doe Address: another street address Phone: 987 555 1234
Another way

mylist = [
    {'name':'John Doe', 'address':'Some address','phone':'123 456 7897'},
    {'name':'Jane Doe', 'address':'another address','phone':'123 555 1230'}
]

for var in mylist:
    print(f"Name: {var['name']} Address: {var['address']} Phone: {var['phone']}")
Output:
Name: John Doe Address: Some address Phone: 123 456 7897 Name: Jane Doe Address: another address Phone: 123 555 1230



RE: lists Name Address Phone - Heyjoe - Jun-21-2020

Thanks menator01. I think that is what I am looking for.