[英]Python-returns object memory address when content of object is desired
Specs: Python 3.3.2 规范: Python 3.3.2
What I was trying to do: 我想做什么:
Create a simple name and employee number dictionary application. Have the user enter a list of names and employee numbers. Your interface should allow a sorted output (sorted by name) that displays employee names followed by their employee numbers.
What I came up with: 我想出了什么:
# enter a list of names of employees
# enter a list of employee numbers
# zip them together
def hrcat():
name = input('Please enter names of employees: ')
number = input('Please enter employee numbers: ')
output = zip(name,number)
print(output)
Question: 题:
When given two lists of names and numbers, it returns the memory address of an object; 当给出两个名称和数字列表时,它返回一个对象的内存地址; something looks like this:
看起来像这样:
>>> hrcat()
Please enter names of employees: a,b,c
Please enter employee numbers: 1,2,3
<zip object at 0x7fea10ce4b90>
I wonder why it returns the memory address instead of the actual content of that object? 我想知道为什么它返回内存地址而不是该对象的实际内容? I googled online but wasn't able to find answers addressing this question.
我在网上搜索,但无法找到解决这个问题的答案。 Thank you for your insights!
感谢您的见解!
In Python 3.x zip
returns an iterator (which looks like <zip object at 0x7fea10ce4b90>
). 在Python 3.x
zip
返回一个迭代器(看起来像<zip object at 0x7fea10ce4b90>
)。 You can apply list
to view the contents, 您可以应用
list
来查看内容,
list(zip(name,number))
Although, if you are just making a dictionary, can forget about the list and use the iterator directly to populate it, 虽然,如果你只是制作一个字典,可以忘记列表并直接使用迭代器来填充它,
dict(zip(name,number))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.