首先明確的是self只有在類的方法中才會有,獨立的函數或方法是不必帶有self的。self在定義類的方法時是必須有的,雖然在調用時不必傳入相應的參數。self名稱不是必須的,在python中self不是關鍵詞,你可以定義成a或b或其它名字都可以,但是約定成俗,不要搞另類,大家會不明白的。下例中將self改為myname一樣沒有錯誤:1 class Person:2 def _init_(myname,name):3
從C語言轉過來學習python的人,總是習慣於在格式化輸出後面加上”,”. 導致在編譯時間出錯。#!/usr/bin/pythonclass Person: def speak(self): print "I can say anything!" def walk(self,distance): print "I can walk %d", %distancepeople = Person()people.speak()people.walk(30) $
1 MotivationFor the task of blogging, you can generate Html file locally, then using metaWeblog API to upload them to your blog hosting site. This workflow has following benefits:There are many ways to generate Html documents, you can choose which
最近剛學Python,就用Python寫了一個演算法,由於不熟練的原因,實現得並不好,但結果是對的,代碼如下:# -*- coding: UTF8 -*-import sysimport copydef init_pass(T): C = {} for t in T: for i in t: if i in C.keys(): C[i] += 1 else: C[i]
Blinky, Button & GPIO examples using PythonContents [hide]1 Examples using Python1.1 Blinky Example1.2 Button Example1.3 GPIO ExampleExamples using PythonThe following application note covers the use of Electrum100's peripherals
Run Python Scripts in SB2 Environmenthttp://lists.scratchbox.org/pipermail/scratchbox-users/2009-September/001533.html http://lists.scratchbox.org/pipermail/scratchbox-users/2008-September/001346.htmlIf you don't want the python to be present in
看書,看程式。 第一個def buildConnectionString(params): """Build a connection string from a dictionary of parameters. Returns string.""" return ";".join(["%s=%s" % (k,v) for k, v in params.items()])if __name__== "__main__": myParams =