1.集合

 #!/usr/bin/env python
# -*- coding:utf-8 -*-
# s=set(['alex','alex','sb'])
# print(s) # s=set('hello')
# print(s) # s={1,2,3,4,5,6}
#添加 add 不能添加重复元素
# s.add('s')
# s.add('3')
# s.add(3)
# print(s) # s.clear()
# print(s) # s1=s.copy()
# print(s1) # s={'sb',1,2,3,4,5,6}
#随机删
# s.pop()
# print(s) #指定删除
# s.remove('sb')
# s.remove('hellol') #删除元素不存在会报错
# s.discard('sbbbb')#删除元素不存在不会报错
# print(s) # python_l=['lcg','szw','zjw','lcg']
# linux_l=['lcg','szw','sb']
# p_s=set(python_l)
# l_s=set(linux_l)
# #求交集
# print(p_s,l_s)
# print(p_s.intersection(l_s))
# print(p_s&l_s)
# #求并集
# print(p_s.union(l_s))
# print(p_s|l_s)
# #差集
# print('差集',p_s-l_s)
# print(p_s.difference(l_s))
# print('差集',l_s-p_s)
# print(l_s.difference(p_s)) #交叉补集
# print('交叉补集',p_s.symmetric_difference(l_s))
# print('交叉补集',p_s^l_s) # python_l=['lcg','szw','zjw','lcg']
# linux_l=['lcg','szw','sb']
# p_s=set(python_l)
# l_s=set(linux_l)
# print(p_s,l_s)
# print('差集',p_s-l_s)
# p_s=p_s-l_s
# p_s.difference_update(l_s)
# print(p_s) # s1={1,2}
# s2={2,3,5}
# print(s1.isdisjoint(s2)) # s1={1,2}
# s2={1,2,3}
# print(s1.issubset(s2))#s1 是s2 的子集
# print(s2.issubset(s1))#False # print(s2.issuperset(s1))#s1 是s2 的父集 # s1={1,2}
# s2={1,2,3}
# s1.update(s2) #更新多个值 # s1.add(1,2,3,4) #更新一个值
# s1.union(s2) #不更新 # print(s1) # s=frozenset('hello')
# print(s)
# names=['alex','alex','wupeiqi']
# #
# names=list(set(names))
# print(names)

2.字符串格式化

 #!/usr/bin/env python
# -*- coding:utf-8 -*-
# msg='i am %s my hobby is %s' % ('lhf','alex')
# print(msg)
#
# msg='i am %s my hobby is %s' % ('lhf',1)
# msg='i am %s my hobby is %s' % ('lhf',[1,2])
# print(msg)
# name='lhf'
# age=19
# msg='i am %s my hobby is %s' % (name,age)
# print(msg) #打印浮点数
# tpl = "percent %.2f" % 99.976234444444444444
# print(tpl) #打印百分比
# tpl = 'percent %.2f %%' % 99.976234444444444444
# print(tpl) # tpl = "i am %(name)s age %(age)d" % {"name": "alex", "age": 18}
# print(tpl)
#
# msg='i am %(name)+60s my hobby is alex' %{'name':'lhf'}
# print(msg)
#
# msg='i am \033[43;1m%(name)+60s\033[0m my hobby is alex' %{'name':'lhf'}
# print(msg) # print('root','x','0','0',sep=':')
# print('root'+':'+'x'+':'+'0','0')

3.format字符串格式化

 #!/usr/bin/env python
# -*- coding:utf-8 -*-
# tpl = "i am {name}, age {age}, really {name}".format(name="seven", age=18) # tpl = "i am {name}, age {age}, really {name}".format(**{"name": "seven", "age": 18})
#
# tpl = "i am {:s}, age {:d}".format(*["seven", 18])
# tpl = "i am {:s}, age {:d}".format("seven", 18) #["seven", 18] l=["seven", 18]
# tpl = "i am {:s}, age {:d}".format('seven',18)
# print(tpl)
#
# tpl = "numbers: {:b},{:o},{:d},{:x},{:X}, {:%},{}".format(15, 15, 15, 15, 15, 15.87623, 2)
# print(tpl)

4.函数

 #!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
y=2*x+1
x=3
y->7
x=3
y->7
'''
# def test(x):
# '''
# 2*x+1
# :param x:整形数字
# :return: 返回计算结果
# '''
# y=2*x+1
# return y
#
# def test():
# '''
# 2*x+1
# :param x:整形数字
# :return: 返回计算结果
# '''
# x=3
# y=2*x+1
# return y
# a=test()
# print(a) #过程:就是没有返回值的函数 # def test01():
# msg = 'test01'
# print(msg)
# #
# #
# def test02():
# msg = 'test02'
# print(msg)
# return msg
# #
# def test03():
# msg = 'test03'
# print(msg)
# return 1,2,3,4,'a',['alex'],{'name':'alex'},None
# #
# def test04():
# msg = 'test03'
# print(msg)
# return {'name':'alex'}
# t1=test01()
# t2=test02()
# t3=test03()
# t4=test04()
# print(t1)
# print(t2)
# print(t3)
# print(t4) # def calc(x,y): #x=2,y=3
# res=x**y
# return x
# return y
# res=calc(2,3)
# print(x)
# print(y)
# print(res)
# # a=10
# # b=10
# # calc(a,b) # def test(x,y,z):#x=1,y=2,z=3
# print(x)
# print(y)
# print(z) #位置参数,必须一一对应,缺一不行多一也不行
# test(1,2,3) #关键字参数,无须一一对应,缺一不行多一也不行
# test(y=1,x=3,z=4) #位置参数必须在关键字参数左边
# test(1,y=2,3)#报错
# test(1,3,y=2)#报错
# test(1,3,z=2)
# test(1,3,z=2,y=4)#报错
# test(z=2,1,3)#报错 # def handle(x,type='mysql'):
# print(x)
# print(type)
# handle('hello')
# handle('hello',type='sqlite')
# handle('hello','sqlite') # def install(func1=False,func2=True,func3=True):
# pass #参数组:**字典 *列表
# def test(x,*args):
# print(x)
# print(args) # test(1)
# test(1,2,3,4,5)
# test(1,{'name':'alex'})
# test(1,['x','y','z'])
# test(1,*['x','y','z'])
# test(1,*('x','y','z')) # def test(x,**kwargs):
# print(x)
# print(kwargs)
# test(1,y=2,z=3)
# test(1,1,2,2,2,2,2,y=2,z=3)
# test(1,y=2,z=3,z=3)#会报错 :一个参数不能传两个值 def test(x,*args,**kwargs):
print(x)
print(args,args[-1])
print(kwargs,kwargs.get('y'))
# test(1,1,2,1,1,11,1,x=1,y=2,z=3) #报错
# test(1,1,2,1,1,11,1,y=2,z=3)
#
# test(1,*[1,2,3],**{'y':1})

day14-python之集合函数字符串格式化的更多相关文章

  1. Python第二天 变量 运算符与表达式 input()与raw_input()区别 字符编码 python转义符 字符串格式化 format函数字符串格式化 帮助

    Python第二天  变量  运算符与表达式  input()与raw_input()区别  字符编码  python转义符  字符串格式化  format函数字符串格式化  帮助 目录 Pychar ...

  2. python学习6—数据类型之集合与字符串格式化

    python学习6—数据类型之集合与字符串格式化 1. 使用id()可以查看一个变量的内存地址: name = 'alex' id(name) 2. 进制转换 十进制转换为二进制等: a = 10 # ...

  3. 【笔记】Python基础二:数据类型之集合,字符串格式化,函数

    一,新类型:集合 集合出现之前 python_l = ['lcg','szw','zjw'] linux_l = ['lcg','szw','sb'] #循环方法求交集 python_and_linu ...

  4. 14.python类型总结,集合,字符串格式化

    借鉴:https://www.cnblogs.com/linhaifeng/articles/5935801.html  https://www.cnblogs.com/wupeiqi/article ...

  5. 【学习笔记】--- 老男孩学Python,day14 python内置函数大全

    参考:  https://www.cnblogs.com/pyyu/p/6702896.html http://www.runoob.com/python3/python3-built-in-func ...

  6. python_05 可变类型与不可变类型、集合、字符串格式化

    可变数据类型与不可变数据类型: 1.可变:列表,字典 2.不可变:字符串,数字,元组 访问顺序: 1.顺序访问:字符串,列表,元组 2.映射:字典 集合 由不同元素组成的集合,集合中是一组无序排列的可 ...

  7. Python基础(十五):Python的3种字符串格式化,做个超全对比!

    有时候,为了更方便.灵活的运用字符串.在Python中,正好有3种方式,支持格式化字符串的输出 . 3种字符串格式化工具的简单介绍 python2.5版本之前,我们使用的是老式字符串格式化输出%s. ...

  8. Python中print/format字符串格式化实例

    Python 字符串格式化使用 "字符 %格式1 %格式2 字符"%(变量1,变量2),%格式表示接受变量的类型.简单的使用例子如下 # 例:字符串格式化Name = '17jo' ...

  9. python的三种字符串格式化方法

    1.最方便的 print 'hello %s and %s' % ('df', 'another df') 但是,有时候,我们有很多的参数要进行格式化,这个时候,一个一个一一对应就有点麻烦了,于是就有 ...

随机推荐

  1. spring boot集成Websocket

    websocket实现后台像前端主动推送消息的模式,可以减去前端的请求获取数据的模式.而后台主动推送消息一般都是要求消息回馈比较及时,同时减少前端ajax轮询请求,减少资源开销. spring boo ...

  2. SpringCloud学习成长之十四 服务注册(consul)

    这篇文章主要介绍 spring cloud consul 组件,它是一个提供服务发现和配置的工具.consul具有分布式.高可用.高扩展性. 一.consul 简介 consul 具有以下性质: 服务 ...

  3. bladex之nacos配置

    blade.yaml #服务器配置server:  undertow:    # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程    io-threa ...

  4. online学习和offline学习

    参考:https://blog.csdn.net/a133521741/article/details/79221015 解释: (1)offline学习:每次训练完一个batch后再更新参数: (2 ...

  5. 【物联网】arduino wifi

    https://www.arduino.cn/forum.php?mod=viewthread&tid=49561 http://dy.163.com/v2/article/detail/DC ...

  6. [ kvm ] 学习笔记 8:Ovirt 基础及使用

    目录- 1. oVirt 功能介绍- 2. oVirt 安装部署    - 2.1 基础准备    - 2.2 安装 ovirt-engine    - 2.3 配置 kvm 主机    - 2.4 ...

  7. MVC4笔记 RedirectResult,RedirectToRoute

    RedirectResult:运行重新导向到其他网址,在RedirectResult的内部,基本上还是以Response.Redirect方法响应HTTP 302暂时导向. eg: public Ac ...

  8. Egg.js中使用sequelize事务

    对数据库的操作很多时候需要同时进行几个操作,比如需要同时改动几张表的数据,或者对同一张表中不同行(row)或列(column)做不同操作,比较典型的例子就是用户转账问题(A账户向B账号汇钱): 1 从 ...

  9. github账户初始化设置

    1.首先在github官网https://github.com/上注册自己的账户: 2.去git官网https://git-scm.com/downloads,根据电脑系统下载合适的版本并安装. 3. ...

  10. html收尾

    <form>input 元素</form> <fieldset ></fieldset > <legend ></legend> ...