qq70191 发表于 2018-8-16 11:28:13

python 学习之 PythonAdvance1

#!/usr/bin/python  
#coding=utf-8
  
#词典
  
'''
  
nl =
  
nl.append(15)
  
print nl
  
bl =
  
print nl + bl
  
dic = {'tom': 11, 'sam': 57, 'lily': 100}
  
print dic['sam']
  
dic['tom']=59
  
print dic
  
dic = {}
  
print dic
  
dic['liwei'] = 89
  
print dic
  
dic = {'lilei': 90, 'lily': 100, 'sam': 57, 'tom':89}
  
for key in dic:
  
    print dic
  
#词典的常用方法
  
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 content
  
f.close()
  
#引入模块
  
import first
  
for i in range(10):
  
    first.laugh()#通过 模块.对象 的方式来调用
  
import a as b             # 引入模块a,并将模块a重命名为b
  
from a import function1   # 从模块a中引入function1对象。调用a中对象时,我们不用再说明模块,即直接使用function1,而不是a.function1。
  
from a import *         # 从模块a中引入所有对象。调用a中对象时,我们不用再说明模块,即直接使用对象,而不是a.对象
  
'''
  
#import My_Modle.module
  
def g(a, b, c):
  
    return a+b+c
  
print(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+f
  
print(h(3,2))
  
print(h(3,2,1))
  
#包裹传递
  
deffunc(*name):
  
    print type(name)
  
    print name
  
func(1, 4, 6)
  
func(5, 6, 7, 8, 1, 2)
  
def func(**dict):
  
    print type(dict)
  
    print dict
  
func(a=1, b=9)
  
func(m=2, n=1, c=11)
  
#解包裹
  
def func2(a, b, c):
  
    printa, b, c
  
args = (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 content
  
f.close()


页: [1]
查看完整版本: python 学习之 PythonAdvance1