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))
mrc06405j on Feb. 12, 2021
This lesson uses python object concepts and syntax which has not been covered in previous courses in the “Introduction to Python” course. A lesson on object concepts, Methods and Attributes should be inserted early on in the course.