看《Python學習筆記 》這本書,想整合與補充一下自己所學的Python知識。
推薦指數:不推薦,講解的內容是Python2的,現在主流是Python3,感覺都塊要Python4了
因爲我已經會Python了,所以看得有點快,基礎知識可以,但大部分不行。
發現的問題:
這個是書上的例子:
我的是mac版pycharm
def f(x):
result = 0
while (x):
result = result + x
x = x - 1
print("result = {}".format(result))(這行是我添加的)
result result
f(4)
然後在while 那一行報錯,提示:縮進錯誤
我同事的是Windows版pycharm,同樣的代碼,沒有問題。
aa="01234567"
def find(string, i):
index = 0
while index < len(string):
if string[index] == i:
return index
index = index + 1 錯誤,要是這麼寫,index永遠別+1了
return -1
print(find(aa,"9"))