Python2 vs Python3
| Python2 | Python3 | |
|---|---|---|
| print syntax |
statementprint "Hello World" |
functionprint("Hello World") |
| int division |
5 / 2 → 2 (same as //) |
5 / 2 → 2.5 (always float) |
| range() | return list |
return iterator |
| variable leakage (comprehension) |
x = 10 y = [x for x in range(5)] print(x) # 4 |
x = 10 y = [x for x in range(5)] print(x) # 10 |
| storage of str | ASCII (7bits) | Unicode (8bits) |
| string formatting |
format"Hi, {}".format(name) |
f-stringf"Hi, {name}" |
Leave a comment