python物件導向

來源:互聯網
上載者:User

標籤:

import cPickle as pimport引入庫,as設定import的別名p.dump(shoplist, f)不明白
os.exists函數檢驗在目錄中是否目錄已經存在。如果沒有,就os.mkdir函數建立。
target = today + os.sep + now + ‘.zip‘
os.sep根據系統的不同,給出不同的分隔字元
zipfile和tarfile
標準庫函數
類方法必須設定一個self變數如果不設初始值,python自動為變數賦值對象本身
class Person://類名    def sayHi(self)://方法名        print ‘Hello, how are you?‘ p = Person()//執行個體化p.sayHi()//使用
屬於一個對象或類的變數被稱為域

self指這個對象本身,是第一個預設參數,如果不給變數賦值,python會調用這個值

當你調用這個對象的方法MyObject.method(arg1, arg2)的時候,這會由Python自動轉為MyClass.method(MyObject, arg1, arg2)

__init__方法,頭尾都是雙底線對象建立時被建立,初始化工作
as關鍵字可以修改第三方函數庫的調用名稱improt webbrowser as web
startswith(‘‘)//驗證開始字串
in//驗證是否在字串
檢查字元if ‘a‘ in name:    print ‘1‘
test.find("a")返回0是找到返回-1是找不到

jointest1 = ["test1","test2","test3"]test2 = "_*_"print test2.join(test1)分割字串
time.strftime()
獲得日期和時間

來自為知筆記(Wiz)

python物件導向

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.