Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Python 2's print vs Python 3's print()

The syntax for print() changed between Python 2 and 3. In Python 2, print was a statement. In Python 3, it has been changed to a built-in function. By changing it to a function, it is now easier to have parameters such as sep and end. You can also now use dependency injection techniques like you could with other functions:

def download(url, log=print):
    log(f'Downloading {url}')
    # ...

def silence(*args):
    pass  # Do not print anything

download('/js/app.js', log=silence)

# ... or
download('/js/app.js', lambda msg: print('[INFO]', msg))

Become a Member to join the conversation.