其他分享
首页 > 其他分享> > tcl dictionary

tcl dictionary

作者:互联网

tcl dictionary

1. 创建字典——set/create

2. 获取字典key的value——get

3. 字典key是否存在——exists

4. 字典键值对数——size

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