Python

Python 2 vs Python 3

28 flashcards · answers and spaced-repetition review in the KnowCard app

Why is Python 2's input() considered dangerous, and what replaced it?
In Python 3, what does the built-in input() return when the user types 2**5?
What does this print in Python 3? ``` print 5 / 2 ```
In Python 3, what does this evaluate to? ``` 5 / 2 ```
In Python 3, what is the result of each? ``` 10 // 4 10.0 // 4 ```
In Python 3, what does -7 // 2 evaluate to?
In Python 3, what does this print? ``` r = map(str, [1, 2, 3]) print(r) ```
In Python 3, what does this print? ``` r = range(5) print(r) ```
You need a list from a Python 2 zip() call after porting to Python 3. What's the fix and why?
In Python 3, what type does dict.keys() return, and what's the practical gotcha?
In Python 3, what type is the result of "text".encode("ascii")?
In Python 3, what does this do? ``` b"abc" + "def" ```
Why does opening a file in binary vs text mode matter more in Python 3 than Python 2?
In Python 3, what's wrong with this and how do you fix it? ``` except ValueError, e: ```
How do you raise an exception with a message in Python 3?
In Python 3, what's the largest int you can store, and what happened to long?
In Python 3, what does type(10 ** 100) return?
What is the 2to3 tool and what does it produce by default?
Why can't 2to3 reliably convert every print statement on its own?
When did Python 2 reach end-of-life, and what does that mean for new code?
In Python 3.3+, what does u"hello" evaluate to, and why is the u prefix even allowed?
After porting to Python 3, import ConfigParser and import Queue both raise ImportError. What happened to these modules?
In Python 2 you used urllib, urllib2, and urlparse. Where did they go in Python 3?
In Python 2 there were the types str and unicode. How do those names map onto Python 3's str and bytes?
Match each piece of syntax to the Python 3.x version that introduced it: f-strings, the walrus := operator, structural pattern matching, async/await.
With the 2to3 migration tool, how do you list the available fixers and run only a subset of them?
What does from __future__ import print_function do in Python 2, and where in the file must such an import appear?
You run python script.py on a Linux box and it dies on Python-3 syntax, even though you know Python 3 is installed. What's the likely cause and fix?

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play
Python 2 vs Python 3 (Python) · KnowCard