- AI Crash Course
- Hadelin de Ponteves
- 192字
- 2021-03-26 16:22:43
Displaying text
We'll begin with the most popular way of introducing any programming language; you'll learn how to display some text in the Python console. The console is a tool that's part of every Python editor, which shows the information we want or displays any errors that occurred (let's hope not to get any!).
The easiest way to show something in our console is to use the print()
method, just like this:
# Displaying text
print('Hello world!')
The text above print
, starting with #
, is called a comment. Comments are excluded when executing code and are only visible to you.
After running this short code in Google Colab, you'll see this displayed:
Hello world!
In conclusion, just put what you want to display into the brackets of the print
method – text surrounded by quotes, as in this example, or variables.
If you're curious about what variables are, that's great – you'll learn about them after this exercise.
Exercise
Using only one print()
method, try to display two or more lines.
Hint: Try using the \n
symbol.
The solution is provided in the Chapter 03/Displaying Text/homework.py
file on the GitHub page.