python基礎實踐(二)

-*-越簡單越快樂-*-# -*- coding:utf-8 -*-# Author:sweeping-monkQuestion_1 = "python中的整數運算"Method_1 = "方法以下:"print(Question_1)print(Method_1)cmd_D = '''>>> 3 + 25>>> 3 - 21>>> 3 * 26>>> 3 / 21.5>>> 3 // 21>>> 3 ** 29>>> 3 ** 327>>> 10 ** 2100>>> 10 ** 61000000>>> 2 + 3*414>>> (2 + 3) * 420'''print(cmd_D)Question_2 = "如何使用函數str()避免類型錯誤?"Method_2 = "寫一個生日祝福來解釋這個問題,請看演示:"print(Question_2)print(Method_2)age = 36#message = "Happy " + age + "rd Birthday!"    #這段age的變量值究竟是數字23仍是字符2和3呢?你執行程序後會發現報類型錯誤。message = "Happy " + str(age)+ "rd Birthday!"     #這裏是把數字23轉換成字符2和3打印出來print(message)Question_3 = "python之禪"print(Question_3)cdm_D_1 = '''>>> import this     The Zen of Python, by Tim PetersBeautiful is better than ugly.Explicit is better than implicit.Simple is better than complex.Complex is better than complicated.Flat is better than nested.Sparse is better than dense.Readability counts.Special cases aren't special enough to break the rules.Although practicality beats purity.Errors should never pass silently.Unless explicitly silenced.In the face of ambiguity, refuse the temptation to guess.There should be one-- and preferably only one --obvious way to do it.Although that way may not be obvious at first unless you're Dutch.Now is better than never.Although never is often better than *right* now.If the implementation is hard to explain, it's a bad idea.If the implementation is easy to explain, it may be a good idea.Namespaces are one honking great idea -- let's do more of those!>>> Tim Peters的《巨蟒之禪》----->代碼指導原則:美勝於醜。外顯優於內隱。簡單賽過複雜。複雜勝於複雜。扁平優於嵌套。疏比密。可讀性是重要的。特殊案件不足以打破規則。雖然實用賽過純粹。錯誤決不能悄無聲息地經過。除非明確沉默。面對模棱兩可,拒絕猜想的誘惑。應該有一個——最好只有一個——顯然是這樣作的。雖然這種方式起初並不明顯,除非你是荷蘭人。如今總比沒有強。雖然如今歷來沒有比如今更好。若是實現很難解釋,那是個壞主意。若是實現容易解釋,那多是個好主意。名稱空間是一個偉大的想法-讓咱們作更多的!> > >'''print(cdm_D_1)
相關文章
相關標籤/搜索