Tcl命令操做實驗-----(12) ---字典

TCL的字典:code

Vivado% dict set colours c1 red
c1 red
Vivado% dict set colours c2 green
c1 red c2 green
Vivado% dict set colours c3 blue
c1 red c2 green c3 blue
Vivado% set cs [dict create c1 "black" c2 "white"]
c1 black c2 white

字典的大小和字典的迭代:get

Vivado% puts [dict size $cs]
2
Vivado% puts [dict size $colours]
3
Vivado% foreach  item  [dict keys $cs] {
set value [dict get $cs $item]
puts $value
}
black
white

字典的鍵和值及某個鍵是否存在:it

Vivado% set colours [dict create c1 "red" c2 "green" c3 "blue"]
c1 red c2 green c3 blue
Vivado% puts [dict keys $colours]
c1 c2 c3
Vivado% puts [dict values $colours]
red green blue
Vivado% puts [dict get $colours c2]
green
Vivado% puts [dict exists $colours c3]
1
Vivado% puts [dict exists $colours c4]
0
相關文章
相關標籤/搜索