- Practical Data Wrangling
- Allan Visochek
- 318字
- 2021-07-02 15:16:09
The print function
I've been taking it for granted so far that the Python shell automatically prints the result of any statement that is entered. However, if you want to see the result of a particular operation inside a Python program, you will need to explicitly print it using the print() function. To use the print() function, you can type print() with the value that you would like to print inside parentheses.
Here are some examples using the print() function:
or example:>> print(0)
>> print(1+1)
>> print('abc')
>> print("abc" == "cba")
The syntax used with the print function may seem a bit strange right now, but it will become more clear when I introduce functions later in the chapter.
There are two areas that the print() function comes in handy. The first of these is to test and debug programs. In order to see whether your program is working properly, or why it is not working properly, it is helpful to look inside the program while it is running. You can do this by placing print() functions in the program where you want to investigate what is happening. To give a really basic example, if a program that outputs a number produces the wrong number, one approach is to print the number at various stages of the program to identify where things go wrong.
The second use of print() functions is to track the progress or status of a program. Processing large datasets can often take a really long time, so it can be helpful to have some sense of how far along the program is and how long it might take to finish. For example, when processing a large dataset row by row, it can be helpful to print out the fraction of rows that have been processed.
- 構(gòu)建高質(zhì)量的C#代碼
- WOW!Illustrator CS6完全自學(xué)寶典
- Visual C# 2008開(kāi)發(fā)技術(shù)實(shí)例詳解
- ServiceNow Cookbook
- 數(shù)據(jù)運(yùn)營(yíng)之路:掘金數(shù)據(jù)化時(shí)代
- 數(shù)據(jù)產(chǎn)品經(jīng)理:解決方案與案例分析
- VB語(yǔ)言程序設(shè)計(jì)
- SharePoint 2010開(kāi)發(fā)最佳實(shí)踐
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)
- Splunk Operational Intelligence Cookbook
- 水晶石影視動(dòng)畫(huà)精粹:After Effects & Nuke 影視后期合成
- Java組件設(shè)計(jì)
- 工業(yè)機(jī)器人操作
- 大型機(jī)系統(tǒng)應(yīng)用基礎(chǔ)
- 基于Quartus Ⅱ的數(shù)字系統(tǒng)Verilog HDL設(shè)計(jì)實(shí)例詳解