Python vs JavaScript language features

I don’t think there’s anything above TL4.

Mods and Admins are above TL4.

1 Like

There’s mod (me :smile:), admin and staff

2 Likes

There’s no TL5 for sure;

Unless you consider Mods TL5, that’s true.

2 Likes

Please keep related to Python vs. JS

3 Likes

That is not really a fair comparison, as range is not required for a loop.


for (let i = 1; i < 10; i += 2) console.log(i) // How do you know when each of these are executed?

Or

i = 1
while i < 10:
  i += 2
  print(i)
3 Likes

Number two yes. The for syntax looks just weird in this case.

1 Like

That’s true, but I was saying that python’s equivalent of the for (init; condition; increment) syntax is range(starting, max, increment).

while loops are pretty much standard across all languages

1 Like

Because in python loops suffer from memory leak. Something that should not happen.

1 Like

What does that mean?

1 Like

It means that variables defined/used in a for loop are not deleted when the form loop ends
If you runs this code

for x in range(0, 5):
    pass

print(x)

In python instead of giving error, it prints 4. This is memory leaking. If you do loops where lot of data is assigned and used in the loop, the memory is not freed once the loop end.

5 Likes

What about this?

for x in range(0, 5):
  pass

del x
1 Like

Sure it works, but it should not be needed to delete x and 99% of people do not …

6 Likes

That’s also why you should use let over var:

for (var i = 0; i < 5; i++) console.log(i);

console.log(i); // 5
for (let i = 0; i < 5; i++) console.log(i);

console.log(i); // ReferenceError: i is not defined
4 Likes

For as much as i dislike JS, it is better in this respect than python,

4 Likes

You like it better than python because there are multiple keywords to define a variable…?

1 Like

Let and var are not the same thing. From W3School (in case of doubt)

Before ES6 (2015), JavaScript had Global Scope and Function Scope.
ES6 introduced two important new JavaScript keywords: let and const.
These two keywords provide Block Scope in JavaScript.
Variables declared inside a { } block cannot be accessed from outside the block:

4 Likes

Didn’t say better than, just agreed this is a weak point for Python

4 Likes

Comparing two different loops is not an accurate comparison:

let i = 1;
while (i < 10) {
  i += 2;
}

Or

i = 1
while i < 10:
  i += 2

Is a fair comparison, in which case we see very little difference and the only preference for one over the other coming down to preference of syntax (brackets or meaningful whitespaces) (and of course bias).

2 Likes