官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 潜江市| 天水市| 阿鲁科尔沁旗| 高密市| 黔西| 博湖县| 资溪县| 吐鲁番市| 萍乡市| 阿克苏市| 鹤壁市| 奉新县| 延寿县| 宽城| 高尔夫| 汕尾市| 保定市| 云和县| 布拖县| 连云港市| 象山县| 大田县| 云阳县| 扬中市| 沁源县| 许昌县| 平江县| 高碑店市| 留坝县| 东方市| 钟山县| 河间市| 尚志市| 长子县| 兴国县| 淳安县| 海盐县| 高雄市| 旬阳县| 宾阳县| 奈曼旗|