前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python 学习之 PythonAdv

python 学习之 PythonAdv

作者头像
py3study
发布2020-01-14 15:34:48
2590
发布2020-01-14 15:34:48
举报
文章被收录于专栏:python3python3
代码语言:javascript
复制
#!/usr/bin/python
#coding=utf-8
#词典
'''
nl = [1, 3, 8]
nl.append(15)
print nl
bl = [2, 3, 5]
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[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 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))
#包裹传递
def  func(*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):
    print  a, 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()
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-07-22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档