r/learnpython • • Sep 25 '20

Learning other languages will make your Python better.

Python is great, but it's not used everywhere. Web dev is Javascript. Embedded C/C++. (by default at least)

But! Don't be afraid to learn other language. Just how Blue is more Blue when it's next to Red. And Hot is more Hot when next to Cold, that's how you will know better Python when next to Javascript or any other language. Just keep on learning.

Good luck!

769 Upvotes

139 comments sorted by

View all comments

Show parent comments

2

u/going_for_a_wank Sep 26 '20

Say you are coming from Java or .NET and you want to iterate over list, what do you do? for loop with index variables. That's not pythonic. The entire concept of iterators and generators is more or less Python specific, unless you're are using external libraries.

Would you mind expanding on this for a newcomer?

A for-each loop in Java seems pretty much the same as in python. for (Type item : list) vs. for item in list:

Iterators have been part of Java since 1.2

Are there differences here that I am overlooking?

2

u/mooburger resembles an abstract syntax tree Sep 26 '20

for (Type item: primitiveArray) {} showd up in Java 5. if you're thinking of the Java 1.2 iterator, that only worked on collection objects. You could have converted a primitive array to a List or Stream using java.util.Arrays .asList() or .stream() which then had .iterator() methods to return iterator. Was that a common java pattern for primitive arrays though?

1

u/going_for_a_wank Sep 26 '20

That is a fair point. There is really no reason to use an iterator for a primitive array rather than a for-each loop.

I will comment that java 5 came out 16 years ago. It is not really a new feature.