gpt4 book ai didi

robotframework - 机器人框架中@和$的区别

转载 作者:行者123 更新时间:2023-12-03 08:51:41 25 4
gpt4 key购买 nike

@{metricList}=    Create List
${tabDictionary}= Create Dictionary
Log ${metricList}
LOG ${tabDictionary}

如果我写@{tabDictionary}= Create Dictionary,它将创建一个数组。如果我写 Log @{metricList} 它会抛出错误?

那么@和$有什么区别呢?这是为什么?

最佳答案

@ 运算符需要一个列表结构(类似于经典编程语言中的数组)。

每当您创建列表或字典时,都会将该变量分配给 $ 变量。

您始终可以使用简单的 $ 变量运算符访问列表变量 (@) 或字典变量 (&)。然而,这将打印变量的全部内容。

要访问列表中的项目或字典中的键/值对,必须使用其相应的运算符。它看起来像这样:

${list_variable}=    Create List    item1    item2    item3
${dictionary_variable}= Create Dictionary key1=value1 key2=value2

这样做会很好地工作:

Log    ${list_variable}
Log ${dictionary_variable}

但是要以数据结构的形式访问其内容,您需要执行以下操作:

Log    @{list_variable}[0]    # prints the first item
Log &{dictionary_variable}[key1] # prints the value assigned to key1

等等

关于robotframework - 机器人框架中@和$的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58602553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com