0

Why can't we print "print(zip(a,b))" or simply "print(c)"?

a=[ "ab", "cd", "ef"]
b=["gh","ij","kl"]
c=zip(a,b) 

if I try

"for i,j in c:
    print(i,j)"

Output:

ab gh

cd ij

ef kl

But unable to print "print(c)", its giving like this "zip object at 0x025088C8 " WHY?

Rajat Bain
  • 11
  • 1

1 Answers1

0

First, your solution won't work because you are considering str only. What would happen in the following case ?

zip([1, 10, 100], ["y", "a", "s"])

You can imagine another representation such as:

list(zip([1, 10, 100], ["y", "a", "s"]))
>>> [(1, 'y'), (10, 'a'), (100, 's')]

But you can read here in the zip function documentation that this function returns an iterator and this behaviour (in python3) is preferable for multiple reasons such as memory.