Mairold M
Mairold M

Reputation: 19

Python lists counting with len() method

I have a problem for counting a list elements in python 3.x.

inimesed = ['John', 'Jane', 'Joe', 'Joeline', 'Parker', 'Allie']

inimesed.append('Paul')

print(inimesed)

len(inimesed)

I can't understand what I do wrong, when I start a program the window doesn't show a number of elements on the list, just empty window with sentence 'Please continue'

Upvotes: 0

Views: 84

Answers (2)

Amjad sibili
Amjad sibili

Reputation: 1149

Well your method won't work on certain compilers

l = [1,2,3]
print (len(l))

This will surely work.

Upvotes: 0

Breno Baiardi
Breno Baiardi

Reputation: 99

I believe your reference book is using python interactive shell, that is why it says that len(item) should show something, but normally it doesnt. That is why using

print(len(item))

is working just fine

in regular files (not interactive shell) to see something on screen you should always use output methods such as print. the objective of python shell is learning, so it prints everything your code returns.

Upvotes: 1

Related Questions