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.

Basic Usage and String Literals

If you’re like most Python users, including us, then you probably started your Python journey by learning about print(). It helped you write your very own Hello Horld one-liner. You can use it to display formatted messages onto the screen and perhaps find some bugs. But if you think that’s all there is to know about Python’s print(), then you’re missing out on a lot!

Keep reading to take full advantage of this underappreciated little function. This course will get you up to speed with using Python print() effectively. Prepare for a deep dive as you go through the sections. You may be surprised how much print() has to offer!

By the end of this course, you’ll know how to:

  • Avoid common mistakes with Python’s print()
  • Deal with newlines, character encodings, and buffering
  • Write text to files
  • Mock print() in unit tests
  • Build advanced user interfaces in the terminal


Sample Code (.zip)

9.8 KB


Course Slides (.pdf)

783.5 KB

Sumanyu on Aug. 1, 2020


I run python 3 on IDLE and the Ascii Bell (\a) doesn’t work.

Sumanyu on Aug. 1, 2020

carriage return also doesn’t work

Christopher Trudeau RP Team on Aug. 1, 2020

Yep, looks like you’re right. IDLE isn’t an operating system shell, it is built as a cross platform REPL based on tkinter. It looks like tkinter doesn’t pass everything down to the operating system and doesn’t fully emulate a terminal.

I tested it on macOS and the bell did nothing. The \r does something, but not what I would consider the “normal” thing – on my system it feeds two lines, instead of just acting as a line feed in the same place.

It also isn’t hooked into some of the normal macOS keyboard mechanisms. I can’t, for example, pop up the character selection menu that makes it easy to type unicode or emjoii.

If you want to play with these things, I would suggest running the code directly in a terminal.

Sumanyu on Aug. 1, 2020

Ok. Thanks! Means we can do nothing to run these commands on IDLE?

Christopher Trudeau RP Team on Aug. 2, 2020

I’ve not used IDLE before. My guess is “no” from what I can see of it, but someone who knows better might know a hack.

Everything you do with print() is dependent on the underlying terminal that is displaying the result. You can also get some weirdnesses happening when you are remotely logged into a machine because the terminal emulation across the connection translates the strings differently.

Sumanyu on Aug. 3, 2020

Ok, thanks!

Become a Member to join the conversation.