print[prɪnt]:打印.
printChinese means print、印刷,That is, print text onto paper.
print( )函數在PythonThe role in will beprint( )The contents of the function parentheses are output to the screen.
print( )函數:Python中的輸出函數.
【功能】將print( )The contents of the function parentheses are printed or output to the screen.
print( )函數由4部分組成:
1.函數名:print
2.英文小括號:( )
3.英文引號(有4種情形)
4.要輸出的內容
【示例】
【溫馨提示1】print( )must be followed by the function( )
小括號,( )
Parentheses are the necessary symbols here.
【溫馨提示2】( )
括號,Symbols such as quotation marks must be in英文輸入法狀態下輸入.
【溫馨提示3】Quotes are used or not depending on what is to be output.
默認情況下,The shortcut key to switch between Chinese and English input methods is【shift】.
【溫馨提示】It must be switched to when typing the code英文輸入狀態
,保證print( )Function parentheses are used英文括號
.
Please write it as it is in the code boxprint(520),然後點擊運行.
print(520)
【終端輸出】
520
點擊運行後,Our code implements the content in parentheses520
output to the computer screen.
Note that the parentheses must be English parentheses,否則會報錯!!!
【錯誤示例】
# The brackets in the following code are input under the Chinese input method
print(520)
【終端輸出】
SyntaxError: invalid character ‘(’ (U+FF08)
點擊運行後,程序會報錯,提示invalid character
,即無效字符
.
invalid[ɪnˈvælɪd]:無效的,不成立的.
character[ˈkærəktə]:字母,符號.
# 括號內沒有引號
print( )
#括號內有單引號
print('')
#括號內有雙引號
print(" ")
#括號內有三引號
print(''' ''')
print(""" """)
1.【無引號】Output numbers and formulas.
2.【單引號】Output characters without single quotes.
3.【雙引號】Output any character.
4.【三引號】Output characters with newlines.
Output numbers or formulas:可以直接用print( )
,括號內不加引號.
【數據類型】輸出的內容數據類型為整數或浮點數.
# 輸出整數
print(2022)
【終端輸出】
2022
# 輸出浮點數(Python中的浮點數類似於數學中的小數)
print(0.7)
【終端輸出】
0.7
# 輸出運算結果
print(1+1)
【終端輸出】
2
當括號內有引號的時候,就是讓計算機原樣輸出引號內的內容.
【數據類型】輸出的內容數據類型為字符串.
Quotes and parentheses are required英文狀態
下輸入.
# 引號內有什麼就輸出什麼
print('2022年7月7日')
【終端輸出】
2022年7月7日
# 引號內有什麼就輸出什麼
print('2022')
【終端輸出】
2022
print(2022)
和 print('2022')
The output is all2022,But the data type itself is inconsistent.
沒有引號輸出的2022數據類型是整數.
有引號輸出的2022數據類型是字符串.
什麼是整數、What is a string is explained in detail in the later chapters.
【相同點】Both double and single quotes can output characters.
【不同點】如果輸出的內容裡含有單引號'
,則print( )Double quotes must be used inside function parentheses.
Because with single quotes the computer cannot identify which single quote is what to output,Which single quote represents a string,So use double quotes to distinguish.
# 輸出的內容Let'sIf there are single quotes, you must use double quotes
print("Let's go home!")
【終端輸出】
Let’s go home!
# 輸出內容Let's 裡有單引號,print()Single quotes are also used in functions,程序就會報錯
print('Let's go home!')
【終端輸出】
SyntaxError: invalid syntax
運行程序後提示invalid syntax
i.e. invalid syntax.
invalid[ɪnˈvælɪd]:無效的,不成立的.
syntax [ˈsɪntæks]:語句、語法.
Triple quotes means entering three single quotes,Or enter three double quotes.
【作用】Use triple quotes to output characters with a newline function,That is, output across lines can be achieved.
# output poetry
print(''' Half floating 二兩清酒 三生有幸 四季有你 ''')
【終端輸出】
Half floating
二兩清酒
三生有幸
四季有你
【溫馨提示】
PythonMedium symbols and punctuation should be used英文
輸入法.
PythonMedium symbols and punctuation should be used英文
輸入法.
PythonMedium symbols and punctuation should be used英文
輸入法.
【錯誤提示】
invalid character:無效字符
invalid syntax:無效語法
Sunset is free
Spring, summer, autumn and winter as well
不要覺得
人生無望
抬頭看
You can be happy too
7
?A.print(3+4)
B.print('3+4')