作為一個新手村村民,今天開始踏出coding的第一步,記錄一下今天碰到的幾個問題。
首先本人環(huán)境和工具:win10? ? python3.5? ? notepad++。
網(wǎng)絡(luò)上教程:
print “xxx”
實際會出現(xiàn)如下報錯:
File "E:\mypython\test", line 1
print "xxx"
SyntaxError: invalid syntax
修正為:print ('xxx')即可,或改‘’為“”
PS:同一語句中,不能重復用“”或‘’
即:
print ("i"said"?do not touch this")
總結(jié):除數(shù)字運算外,print的內(nèi)容都需要加()并帶 “”或‘’。
另外附上幾個簡單的小作業(yè)
1:(練習print的格式和敲字)
print ("hello world")
print ("hello again")
print ("i like typing this.")
print ("this is fun.")
print ("yay!printing.")
print ("i'd much rather you 'not'.")
print ('i "said" do not touch this.')
改為一行顯示:(print多個字串)
print ("hello world", "hello again", "i like typing this", "this is fun", "yay!printing", "i'd much rather you 'not'", 'i "said" do not touch this')
2:(了解#注釋)
print ('i could have code like this.') # and the comment after is ignored
# you can also use a comment to "disable" or comment out a piece of code:
#print ("this won't run.")
print ("this will run.")
3:(運用#注釋,理解整個小程序的意思)
print ("i will now count my chickens:")
# 計算母雞和公雞的數(shù)量
print ("hens", 25 + 30 / 6)
print ("roosters", 100 - 25 * 3 % 4)
# 計算雞蛋的數(shù)量
print ("now i will count my eggs:")
# 計算下列式子
print ( 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)
# 判斷:3+2是否小于5-7
print ("is it true that 3 + 2 < 5 - 7?")
# 運算并判斷
print (3 + 2 < 5 - 7)
print ("what is 3 + 2?", 3 + 2)
print ("what is 5 - 7?", 5 - 7)
# 輸出結(jié)果
print ("oh!that is why it's false.")
# 更多練習
print ("how about some more?")
# 判斷真?zhèn)?/p>
print ("is it greater?", 5 > -2)
print ("is it greater or equal?", 5 >= -2)
print ("is it less or euqal?", 5<= -2)
以上是今天的問題記錄。