- 字典的定义
var dict1=[“swift”:“雨燕”,“phyton”:“大蟒”,“java”:“爪哇国”]
//dict1的长度:3
print(dict1.count)
var dict2:[String:String]=[“swift”:“雨燕”,“phyton”:“大蟒”,“java”:“爪哇国”]
var dict3:Dictionary<String,String>=[“swift”:“雨燕”,“phyton”:“大蟒”,“java”:“爪哇国”]
- 空字典的定义
var empty1:[Int:String]=[:]
var empty2:Dictionary<String,String>=[:]
var empty3=String:String
- 判断是否为空
print(dict1.isEmpty)
取值print(dict1[“java”]!)
- 字典的特点:1)无序 2)键不能重复
let d1=[1:“a”,2:“b”,:“d”]
let d2=[2:“b”,1:“a”,3:“d”]
print(d1d2)