当前位置:网站首页>Dictionary, use of sets, conversion of data types
Dictionary, use of sets, conversion of data types
2022-07-19 07:01:00 【I'm Zha Zha Hui】
dict Use
dict Extended dictionary length in ( many-ways )
dict_var = {
1: 2, 3: 4}
dict_var.update(((5, 6), [7, 8]))
dict_var.update(qwe=1)
dict_var.setdefault('q', 'e')
dict_var[9] = 10
print(dict_var)
# {1: 2, 3: 4, 5: 6, 7: 8, 'qwe': 1, 'q': 'e', 9: 10}
dict Get all the key, Get all value, Get all item
dict_var = {
1: 2, 3: 4}
var1 = dict_var.keys()
var2 = dict_var.values()
var3 = dict_var.items()
print(var1) # dict_keys([1, 3])
print(var2) # dict_values([2, 4])
print(var3) # dict_items([(1, 2), (3, 4)])
dict Through a nonexistent key To get the value ( No error is required )
dict_var = {
1: 2, 3: 4}
var1 = dict_var.setdefault(4)
print(var1) # None
var2 = dict_var.get(4)
print(var2) # None
set Use
Define empty sets
set_var = set()
print(set_var) # set()
set in , Difference set , Ask for a collection , Find the intersection ( Requires operation on the original set )
set_var1 = {
1, 2, 3, 4}
set_var2 = {
1, 3, 5, 7}
# set_var1.difference_update(set_var2)
# print(set_var1) # {2, 4}
# set_var1.intersection_update(set_var2)
# print(set_var1) # {1, 3}
set_var2.update(set_var1)
print(set_var2) # {1, 2, 3, 4, 5, 7}
Add an element
set_var1 = {
1, 2, 3, 4}
set_var1.add(5)
print(set_var1) # {1, 2, 3, 4, 5}
Delete an element ( Using a variety of methods )
set_var1 = {
1, 2, 3, 4}
set_var1.discard(1)
print(set_var1) # {2, 3, 4}
set_var1.remove(2)
print(set_var1) # {3, 4}
var = set_var1.pop()
print(set_var1) # {4}
Data type conversion
- Will float , String to integer
- The integer , String to floating point
- Binary , octal ,16 Base to 10 Base number
- take 10 Base to zero , Binary system , octal ,16 Base number
- Convert string to byte
- Convert bytes to strings
- take ascii Code to string
- Converts a string to ascii code
print(int(1.1)) # 1
print(int("1")) # 1
print(float(1)) # 1.0
print(float("1.3")) # 1.3
print(int("0b100", base=2))
print(int("0o100", base=8))
print(int("0x100", base=16))
print(bin(4))
print(oct(64))
print(hex(256))
print(bytes(' Assad ', encoding='UTF-8'))
print(str(b'\xe9\x98\xbf\xe8\x90\xa8\xe5\xbe\xb7', encoding="UTF-8"))
print(chr(97))
print(ord('a'))
边栏推荐
- [automated testing] - robotframework practice (III) writing test cases
- Deploy zabbix-agaent2 and verify
- 函数与随机数
- opensuse 安装网易云音乐(tumbleweed)(leap)
- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
- Solve the problem that the unit test coverage of sonar will be 0
- [automated testing] - robotframework practice (I) building environment
- 字典、元组和列表的使用及区别,
- 企业或个人域名备案怎么弄
- 103.53.124.X IP段BGP线路和普通的专线有什么区别
猜你喜欢

Xiaodi network security - Notes (4)

Galaxy Kirin server system building local and LAN Yum source

Tianyi cloud Hangzhou virtual machine (VPS) performance evaluation

中国知网论文free下载的方法
高防服务器是如何确认哪些是恶意IP/流量?ip:103.88.32.XXX

Ucloud Shanghai arm cloud server evaluation

解决sonar的单元测试的覆盖率会为0问题

Application case of CS brand SD NAND in air quality inspection industry

小迪网络安全-笔记(5)

STEAM游戏高主频i9-12900k 搭建CS:GO服务器
随机推荐
Class is coming. Roll call is needed
Minecraft bedrock BDS service tutorial
Alibaba cloud Hangzhou arm ECS performance evaluation
判断凹凸(数学题)
寄居蟹和海葵
Tower of Hanoi 2 (function)
day01(Flume)
字典、元组和列表的使用及区别,
Good partner of single chip microcomputer - CS Genesis SD NAND flash
各大云服务厂商 轻量应用服务器 性能评测对比,阿里云、腾讯云、华为云、Ucloud
文本三剑客之awk命令--截取
Xiaodi network security notes - Information Collection - architecture, construction, WAF (8)
Steam游戏服务器配置选择 IP
阿里云 杭州 ARM 云服务器性能评测
银河麒麟桌面操作系统V10SP1(X86)安装SQL Developer
linxu下调试微信调一跳(Fedora 27)
Huawei routing port mapping
阿里云、腾讯云、华为云、Ucloud(优刻得)、天翼云 的云服务器性能测试和价格对比
Servlet 笔记
【无标题】