I'm learning Python, using CPython. I'm reading how to use lists and tuples properly, so I've designed a really simple program to see if I know what I'm doing, but as I can see, there is something wrong in theory and I don't know what is
I've designed 2 functions: foo and foo2, intendend to print the same result, but it's not.
# Wrong output
def foo(v):
print(v[:][0])
# Right output
def foo2(v):
for i in range(0, 2):
print(v[i][0])
v = [('ABC', 'DEF', 1), ('ABC2', 'DEF2', 2)]
foo(v)
foo2(v)
RESULT: Output from foo: ('ABC', 'DEF', 1) Output from foo2: ABC ABC2
EXPECTED: Output from foo: ABC ABC2 Output from foo2: ABC ABC2
What is hapenning here?