当前位置:网站首页>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
- 轻重搭配(贪心)
- Wireshark packet capture: message information
- Galaxy Kirin server system building local and LAN Yum source
- UCloud(优刻得) 上海 ARM 云服务器评测
- Comparison between CS brand SD NAND and SPI NAND
- Judge concave convex (mathematical problem)
- 数据保护/磁盘列阵RAID保护 IP段103.103.188.xxx
- Slag learning path (1) output the calendar page of a certain month of a certain year
- IP103.53.125.xxx IP地址段 详解
猜你喜欢

mysql的复习总结
![[CS Genesis] comparative analysis of advantages and disadvantages of SD NAND and raw NAND](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[CS Genesis] comparative analysis of advantages and disadvantages of SD NAND and raw NAND

解决sonar的单元测试的覆盖率会为0问题
![[jmeter] TCP Sampler](/img/ac/3b08db8808d84eb144262d78880050.png)
[jmeter] TCP Sampler
![Minecraft整合包 [GTNH]格雷科技:新视野 服务器搭建教程](/img/59/d5f226f57cfd7d28d5a76ff38fae16.png)
Minecraft整合包 [GTNH]格雷科技:新视野 服务器搭建教程

文本三剑客之awk命令--截取

How to determine the electronic gear ratio of servo motor?

【自动化测试】——robotframework实战(一)搭建环境

Zuul路由的映射规则配置

小迪网络安全-笔记 加密编码算法(6)
随机推荐
Performance test and price comparison of cloud servers of Alibaba cloud, Tencent cloud, Huawei cloud, ucloud and Tianyi cloud
Decipher password (comprehensive)
部署zabbix-agaent2与验证
Deploy zabbix-agaent2 and verify
opensuse 安装网易云音乐(tumbleweed)(leap)
Performance evaluation and comparison of lightweight application servers of major cloud service manufacturers, Alibaba cloud, Tencent cloud, Huawei cloud, and ucloud
BigDecimal中divide方法
小迪网络安全-笔记 加密编码算法(6)
阿里云 杭州 ARM 云服务器性能评测
ACK攻击是什么意思?ACK攻击怎么防御
搭建一个网站都需要那些东西
判断凹凸(数学题)
配置树莓派3b+搭建个人网站
ANAME
Gnome 安装扩展插件(40.1版本,opensuse tumbleweed)。
ssh远程登录服务
[automated testing] - robotframework practice (I) building environment
轻重搭配(贪心)
邮资范围(数组 or +函数)
freebsd12 安装gnome3图形界面