博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python学习笔记Day4
阅读量:7031 次
发布时间:2019-06-28

本文共 1916 字,大约阅读时间需要 6 分钟。

1、set集合

    set集合是一种无序且不重复的集合

   添加功能:

s1 = set() s1.add("wang") print(s1) difference功能(从当前集合里找出不同的元素并生成一个新的集合):
s1 = set(["wang","pan","lai"]) s2 = s1.difference(["wang","pan"]) print(s2) 结果:{'lai'} difference_update(从当前集合里去掉重复的元素,不生成新的集合):
s1 = set(["wang","pan","lai"]) s1.difference_update(["pan","lai"]) print(s1) 结果:{'wang'} 1、队列 单项队列(queue):先进先出 双向队列(collections):两边都可以进和取 2、字典{}、元组()、列表[]

 

 

 
3、深copy(copy.deepcopy())和浅copy(copy.copy())    对于数字和字符串来说,两者的结果内存地址是一样的 4、函数 函数里的try语句:

 

 
# -*- coding:utf-8 -*- # Author: cslzy # Email: lizhenyang_2008@163.com # Description:send something to someone. # Date: 20151104 18:33:08 import smtplib from email.mime.text import MIMEText as mt def mail(user):     ret = 'ture'     try:         msg = MIMEText('你好!','plaon','utf-8')         msg['From'] = formataddr(['王盼','wangpan0810@126.com'])         msg['To'] = formataddr(['王盼','1471333927@qq.com'])         msg['Subject'] = '主题'         server = smtplib.SMTP('smtp.126.com',25)         server.login('wangpan0810@126.com','密码')         server.sendmail('wangpan0810@126.com',[user,],msg.as_string())         server.quit()     except Exception:         ret = 'false'     return ret ret = mail('1471333927@qq.com') print(ret)
 

   默认参数必须写在后面。

动态参数(*:元组,**字典):
def han(*arg,**karg):     print(arg,type(arg))     print(karg,type(karg)) han(7,89,3,62,n1=78,n2=88)
def han(*arg,**karg):     print(arg,type(arg))     print(karg,type(karg)) l1 = [7,89,3,62] l2 = {'n1':78,'n2':88} han(*l1,**l2)
#l1 = '{0} is {1}' l1 = '{name} is {role}' n1 = {'name':'ren','role':'dashen'} #l2 = l1.format('ren','dashen') #l2 = l1.format(name='ren',role='dashen') l2 = l1.format(**n1) print(l2) 简单函数lambda表达式:

 

如果要在python2的py文件里面写中文,则必须要添加一行声明文件编码的注释,否则python2会默认使用ASCII编码。

参考:http://blog.csdn.net/arbel/article/details/7957782

python内置函数: http://www.runoob.com/python/python-built-in-functions.html
 

 

 

 

 
      

转载于:https://www.cnblogs.com/wp0810/p/7158131.html

你可能感兴趣的文章
类图标注的使用范例
查看>>
NumberFormat注解 DateTimeFormat
查看>>
[转载]PV操作简单理解
查看>>
Acm Dima and Lisa的题解
查看>>
2017 ZSTU寒假排位赛 #7
查看>>
MSSQL_打开xp_cmdshell
查看>>
(转)win7英文目录和中文目录,文件夹的别名
查看>>
MySQL进阶
查看>>
mybatis分页 -----PageHelper插件
查看>>
从移动硬盘启动电脑与重装注意事项
查看>>
深入浅出Tomcat系列
查看>>
从网页提取的关键字
查看>>
杭州手持式超声波流量计的特点汇总
查看>>
位运算符
查看>>
【OCP-12c】CUUG 071题库考试原题及答案解析(18)
查看>>
Centos7系统如何不重启系统识别新添加的硬盘?
查看>>
【Unity Shader】自定义材质面板的小技巧
查看>>
icon文件操作
查看>>
BeatSaber节奏光剑双手柄MR教程
查看>>
分组聚合
查看>>