"""
集合:set
1、由不同元素组成,
2、无序
3、不可变:数字、字符串、元组
不可变类型
"""
s = {1, 2, 3, 4, 1, 6, 3, 4, 5, 6}
print(s) t = {'hello', 'ssad', 'asd', 'asd', 'hello'}
print(t) s1 = set('hello')
print(s1) # s2 = set(['cui', 'hai', 'cheng', 'cui'])
# print('s2:', s2) ss = {1, 2, 3, 4, 5, 6} ss.add('3') # 添加元素,只能一个值
ss.add(32)
print(ss) # ss.clear() # 清空集合
# print(ss) s3 = ss.copy()
print(s3) ss.pop() # 随机删除
print(ss)
# ss.remove('3') # 指定元素删除,不存在会报错
print(ss) ss.discard('ewrewrewr') # 删除元素不存在,不会报错
print(ss) python_l = ['cui', 'hai', 'cheng', 'pipi', 'anan']
linux_l = ['cui', 'pipi', 'cheng', 'kele', 'honr'] p_l = set(python_l)
l_l = set(linux_l) print(p_l, l_l)
print(p_l.intersection(l_l)) # 求p_l中和l_l一样的元素
print(p_l & l_l) # 求p_l和l_l交集 print(p_l.union(l_l)) # 求p_l和l_l一共的元素
print(p_l | l_l) # 求p_l和l_l并集 print("差集:", p_l - l_l) # 求差集
print('chaji:', l_l - p_l)
print(p_l.difference(l_l)) print(p_l.symmetric_difference(l_l)) # 交叉补集
print(p_l ^ l_l) s4 = {1, 2}
s5 = {3, 4}
print(s4.isdisjoint(s5)) # 没有交集的时候返回True s6 = {1, 2, 3}
s7 = {1, 2}
print(s7.issubset(s6)) # s7是s6的子集 print(s6.issuperset(s7)) # s6是s7的父集 s7.update(s6) # 更新多个值
print(s7) # 集合变为不可变的
s9 = frozenset('hello')
print(s9) s8 = ['pipi', 'cui', 'pipi', 'cui', 'cheng']
names = list(set(s8))
print(names) """
字符串格式化
%s 字符串,万能接
%d 整形数字
%f 浮点数(保存六位) %.2f 保留两位
字典形式
"""
print('I am %s ,my hobby is %s' % ('cui', 'read book'))
print('I am is %d' % 20)
print('my percent is %.2f %%' % 98.44444)
print('I am %(name)s age %(age)d' % {'name': 'cui', 'age': 20}) """
format 格式化
""" tpl = "i am {}, age {}, {}".format("seven", 18, 'alex')
print(tpl) tp2 = "i am {}, age {}, {}".format(*["seven", 18, 'alex'])
print(tp2) tp3 = "i am {0}, age {1}, really {0}".format("seven", 18)
print(tp3) tp4 = "i am {0}, age {1}, really {0}".format(*["seven", 18])
print(tp4) tp5 = "i am {name}, age {age}, really {name}".format(name="seven", age=18)
print(tp5) tp6 = "i am {name}, age {age}, really {name}".format(**{"name": "seven", "age": 18})
print(tp6) tp7 = "i am {0[0]}, age {0[1]}, really {0[2]}".format([1, 2, 3], [11, 22, 33])
print(tp7) tp8 = "i am {:s}, age {:d}, money {:f}".format("seven", 18, 88888.1)
print(tp8) tp9 = "i am {:s}, age {:d}".format(*["seven", 18])
print(tp9) tpl0 = "i am {name:s}, age {age:d}".format(name="seven", age=18)
print(tpl0) tpl1 = "i am {name:s}, age {age:d}".format(**{"name": "seven", "age": 18})
print(tpl1) tpl2 = "numbers: {:b},{:o},{:d},{:x},{:X}, {:%}".format(15, 15, 15, 15, 15, 15.87623, 2)
print(tpl2) tpl3 = "numbers: {:b},{:o},{:d},{:x},{:X}, {:%}".format(15, 15, 15, 15, 15, 15.87623, 2)
print(tpl3) tpl4 = "numbers: {0:b},{0:o},{0:d},{0:x},{0:X}, {0:%}".format(15)
print(tpl4) tpl5 = "numbers: {num:b},{num:o},{num:d},{num:x},{num:X}, {num:%}".format(num=15) print(tpl5)

  

python第五天---集合与format格式化的更多相关文章

  1. Python学习(五)—— 集合和字符格式化

    数据类型和变量的总结 字符串 数字 列表 元组 字典 分类 1.可变不可变: 可变(即修改变量值以后id不改变):列表.字典 不可变(即修改变量值以后id改变):字符串.数字.元组 2.访问顺序: 直 ...

  2. Python基础 之 set集合 与 字符串格式化

    数据类型的回顾与总结 可变与不可变1.可变:列表,字典2.不可变:字符串,数字,元组 访问顺序:1.直接访问:数字2.顺序访问:字符串,列表,元祖3.映射:字典 存放元素个数:容器类型:列表,元祖,字 ...

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

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

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

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

  5. 【387】Python format 格式化函数

    参考:Python format 格式化函数 # 保留小数点后两位 f'{3.1415926:.2f}' # 带符号保留小数点后两位 f'{3.1415926:+.2f}' f'{-1:+.2f}' ...

  6. Python format 格式化函数。

    Python format 格式化函数  Python 字符串 Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能. 基本语法是通过 {} 和 ...

  7. 【Python】Python format 格式化函数(转帖)

    https://www.runoob.com/python/att-string-format.html Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符 ...

  8. python format格式化函数用法

    python format格式化函数用法 原文 Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能. 基本语法是通过 {} 和 : 来代替以前 ...

  9. Python format格式化函数

    参考资料:https://www.runoob.com/python/att-string-format.html 在学习Python的时候碰到了一个很有趣的格式化输入的技巧,下面记录在此. Pyth ...

随机推荐

  1. 6.linux 用户和权限的建立

    一.用户和权限的建立       su  用户名       切换用户,如果是root用户切换其他用户,不需要输入密码.     exit  可以切换回上一个用户       linux 操作系统用户 ...

  2. AWS 配置IPv6

  3. shell 脚本 - 关于循环的应用

    array=('Brand' 'BrandInfo' 'BrandBaojia' 'VehicleType' 'BrandBaoyang' 'Youhui' 'Config' \ 'Comment' ...

  4. QSplitter的使用案例

    #include <QApplication> #include <QSplitter> #include <QTextEdit> #include <QTe ...

  5. 一百四十:CMS系统之使用flask-paginate实现分页功能

    官方文档:https://pythonhosted.org/Flask-paginate/ 安装:pip install flask-paginate 在没有分页的情况下,默认会加载所有内容 在con ...

  6. 源码搭建LAMP环境

    需要准备的安装包以及下载地址(只是一个大概地址,版本和下载方式需要自行选择): Apache http://httpd.apache.org/  httpd主程序包(http server) MySQ ...

  7. tornado之自定义form表单验证

    直接上链接吧:银角的地址 源码下载链接:点我点我点我...

  8. (十七)Centos之安装配置tomcat8

    第一步:下载Tomcat8压缩包 进入 http://tomcat.apache.org/download-80.cgi 下载tar.gz压缩包 第二步:用ftp工具把压缩包上传到/home/data ...

  9. 【Leetcode_easy】703. Kth Largest Element in a Stream

    problem 703. Kth Largest Element in a Stream 题意: solution1: priority_queue这个类型没有看明白... class KthLarg ...

  10. linux EXT4格式分区扩容

    1.查看现有的分区大小  2.关机增加磁盘大小为100G  3.查看磁盘扩容后状态 lsblk或dh -TH 4.进行分区扩展磁盘,保留根目录的起止位置.  5.删除根分区,不要保存  6.创建分区, ...