【Swift 60秒】13 - Dictionaries

本文介绍了Python中的字典数据结构,它允许通过自定义标识符(如字符串)来存储和检索数据。以歌手身高为例,展示了如何创建和访问字典元素。此外,提到了类型注解中字典的表示方法。文章适合Python初学者了解和掌握字典的使用。
摘要由CSDN通过智能技术生成

0x00 Lesson

Dictionaries are collections of values just like arrays, but rather than storing things with an integer position you can access them using anything you want.

The most common way of storing dictionary data is using strings. For example, we could create a dictionary that stores the height of singers using their name:

let heights = [
	"Taylor Swift": 1.78,
	"Ed Sheeran": 1.73
]

Just like arrays, dictionaries start and end with brackets and each item is separated with a comma. However, we also use a colon to separate the value you want to store (e.g. 1.78) from the identifier you want to store it under (e.g. “Tavlor Swift”).

These identifiers are called keys, and you can use them to read data back out of the dictionary:

heights["Taylor Swift"]

Note:
When using type annotations, dictionaries are written in brackets with a colon between your identifier and value types. For example,
[String: Double] and [String: String]


0x01 我的小作品

欢迎体验我的作品之一:小五笔
五笔学习好帮手
App Store 搜索即可~


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

豪冷啊

你的鼓励是对我的认可!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值