首页 > 其他分享 >tcl dictionary

tcl dictionary

时间:2022-08-17 06:44:12浏览次数:75  
标签:set puts dictionary get tcl dict key my

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

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
From: https://www.cnblogs.com/movit/p/16593585.html

相关文章

  • make clean 与 make distclean 的区别及其他
    原文地址:https://www.jianshu.com/p/9920cd513c2b/区别:makeclean仅清除之前编译的可执行文件及配置文件。makedistclean要清除所有生成的文件。Makefile在符合......
  • Bash Perl Tcl syntax diff
    BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexadecimalbash2#[0~1]0[0~7]0x[0~f]or0X[0~f]perl0b[0~1]0[0~7]0x[0~f]tcl0b[......