tcl dictionary
作者:互联网
tcl dictionary
1. 创建字典——set/create
- dict create key1 value1 ... keyn valuen [multi keys/values]
- dict set dict_name key value [single key/value]
- dict set/create live demo
2. 获取字典key的value——get
- dict get dict_name key
- dict get live demo
3. 字典key是否存在——exists
- dict exists dict_name key
- dict exists live demo
4. 字典键值对数——size
- dict size dict_name
- dict size live demo
Appendix
1. tcl set/create
# tcl dictionary
# dict set command
# dict set每次设置一对键值,多次对同一个字典设置,形成多对键值
dict set my_dict1 a 1
puts $my_dict1
dict set my_dict1 b 2
puts $my_dict1
# dict create command
# dict creat keyn valuen,没有dict_name,配合set dict_name [dict create key1 value1 ... keyn valuen]
set my_dict2 [dict create name1 "SQ" name2 "KingR" name3 "Sinri"]
puts [dict get $my_dict2 name1]
2. tcl get
# dict get command, key name不需要加$符号
set my_dict {a 1 b 2 c 3 d 4 e 5}
puts [dict get $my_dict a]
puts [dict get $my_dict c]
puts [dict get $my_dict e]
3. tcl exists
# dict exists command, key name不需要加$符号
set my_dict {a 1 b 2 c 3 d 4 e 5}
puts [dict exists $my_dict a]
puts [dict exists $my_dict f]
标签:set,puts,dictionary,get,tcl,dict,key,my 来源: https://www.cnblogs.com/movit/p/16593585.html