作為一個(gè)新手村村民,今天開始踏出coding的第一步,記錄一下今天碰到的幾個(gè)問題浪默。
首先本人環(huán)境和工具:win10? ? python3.5? ? notepad++浪箭。
網(wǎng)絡(luò)上教程:
print “xxx”
實(shí)際會(huì)出現(xiàn)如下報(bào)錯(cuò):
File "E:\mypython\test", line 1
print "xxx"
SyntaxError: invalid syntax
修正為:print ('xxx')即可,或改‘’為“”
PS:同一語句中枪汪,不能重復(fù)用“”或‘’
即:
print ("i"said"?do not touch this")
總結(jié):除數(shù)字運(yùn)算外,print的內(nèi)容都需要加()并帶 “”或‘’主儡。
另外附上幾個(gè)簡(jiǎn)單的小作業(yè)
1:(練習(xí)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多個(gè)字串)
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:(運(yùn)用#注釋仇箱,理解整個(gè)小程序的意思)
print ("i will now count my chickens:")
# 計(jì)算母雞和公雞的數(shù)量
print ("hens", 25 + 30 / 6)
print ("roosters", 100 - 25 * 3 % 4)
# 計(jì)算雞蛋的數(shù)量
print ("now i will count my eggs:")
# 計(jì)算下列式子
print ( 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)
# 判斷:3+2是否小于5-7
print ("is it true that 3 + 2 < 5 - 7?")
# 運(yùn)算并判斷
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.")
# 更多練習(xí)
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)
以上是今天的問題記錄县恕。