python 學習之 PythonAdvance1

來源:互聯網
上載者:User

標籤:python   advance   

#!/usr/bin/python#coding=utf-8#詞典‘‘‘nl = [1, 3, 8]nl.append(15)print nlbl = [2, 3, 5]print nl + bldic = {‘tom‘: 11, ‘sam‘: 57, ‘lily‘: 100}print dic[‘sam‘]dic[‘tom‘]=59print dicdic = {}print dicdic[‘liwei‘] = 89print dicdic = {‘lilei‘: 90, ‘lily‘: 100, ‘sam‘: 57, ‘tom‘:89}for key in dic:    print dic[key]#詞典的常用方法print dic.keys()print dic.values()print dic.values()del dic[‘lilei‘]dic.clear()print len(dic)#文字檔的輸入輸出f = open("test.txt", "r")content = f.readline()print content#輸入#f.write(‘I like apple!‘)content = f.readlines()print contentf.close()#引入模組import firstfor i in range(10):    first.laugh()  #通過 模組.對象 的方式來調用import a as b             # 引入模組a,並將模組a重新命名為bfrom a import function1   # 從模組a中引入function1對象。調用a中對象時,我們不用再說明模組,即直接使用function1,而不是a.function1。from a import *           # 從模組a中引入所有對象。調用a中對象時,我們不用再說明模組,即直接使用對象,而不是a.對象‘‘‘#import My_Modle.moduledef g(a, b, c):    return a+b+cprint(g(1, 2, 3))#關鍵字傳遞print(g(c=3, b=2, a=1))print(g(1, c=3, b=2))#參數預設值def h(d, e, f=10):    return d+e+fprint(h(3,2))print(h(3,2,1))#包裹傳遞def  func(*name):    print type(name)    print namefunc(1, 4, 6)func(5, 6, 7, 8, 1, 2)def func(**dict):    print type(dict)    print dictfunc(a=1, b=9)func(m=2, n=1, c=11)#解包裹def func2(a, b, c):    print  a, b, cargs = (1, 2, 5)func2(*args)dict = {‘a‘: 1, ‘b‘: 2, ‘c‘: 3}func(**dict)f = open(‘My_Module/record.txt‘, ‘a+‘)f.write(‘\n I like apple!‘)f = open(‘My_Module/record.txt‘, ‘r‘)for i in range(10):    content = f.readline()    print contentf.close()

本文出自 “小陌成長之路” 部落格,謝絕轉載!

python 學習之 PythonAdvance1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.