0

I have this rather simple loop

cities = ['Merano', 'Madrid', 'New York', 'Bangkok']
countries = ['Italy', 'Spain', 'USA']

for index, city in enumerate(cities):
    print('This is index:', index)
    print('This is city:', city)
    print('The length of the list \'cities\' is: ', len(cities))
    print(print('The length of the list \'countries\' is: ', len(countries)))
    print(countries[index])
    print(5 * '#')

I expect it to break. However, what I did not expect is this output.

This is index: 0
This is city: Merano
The length of the list 'cities' is:  4
The length of the list 'countries' is:  3
None
Italy
#####
This is index: 1
This is city: Madrid
The length of the list 'cities' is:  4
The length of the list 'countries' is:  3
None
Spain
....

Where is the none coming from? I do not print this, nor do I execute something where I'd expect this to be printed...

3 Answers 3

4

you used print(print()) in print(print('The length of the list \'countries\' is: ', len(countries))) use

print('The length of the list \'countries\' is: ', len(countries))`
Sign up to request clarification or add additional context in comments.

Comments

2

Because you have 2 print commands

print(print('The length of the list \'countries\' is: ', len(countries)))

1 Comment

Oh wow... I should have looked closer ;) Thanks!
1
print(print('The length of the list \'countries\' is: ', len(countries)))

in the above line you are printing print functions output.

If you look at function Def it doesn't have a return type so you are getting None from the inner print() statement.

Also a remark- fix the index check for index > len(countries)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.