2.7v3.5

Comparisons

Strings

2

3

Default 8-bit String

Default unicode

u'Hi' for unicode

b'Hi' for 8-bit string

Division

2, truncates by default:

3/2 => 1

3.0//2 => 1.0

3, // for truncating

3.0/2 => 1

3//2 => 1

Iterators 3 vs Lists 2

Optimized native functions used iterators in 3 vs lists in 2

i.e range, map, filter, dict.[ft], zip

Print

In 2 can do print Hello

In 3, print is a regular ft so must include () print(Hello)

Raw Input in 2.7 s now input in 3

2.7 Specific Stuff

Import python 3 functionality(good for migration and changes fundamental python props), needs to be near top of code because imported differently and changes things about language

3.5 New Features

Dictionary Comprehensions

{k: v for k, v in stuff}

Iterable Unwrapping

Objects

python 3 has different objects or something look it up

Formatting Print

Typing Hinting

This doesn't make python a staticly typed language suddenly, but basically inline comments

Type Alias

Dataclass

Actually creates a __str and __init for you

Actually Type Checking

Use pycharm or something with this (atom has a mypy plugin)

OR

pip install mypy

mypy [file]

Last updated