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

If I write @{tabDictionary}= Create Dictionary, it will create an array. If I write Log @{metricList} it throws error?

Then what is the difference between @ and $? Why is that?

A M Akankshit
  • 21
  • 1
  • 5
  • Possible duplicate of [In Robot Framework, what is the difference between a List Variable and a Scalar Variable containing a list?](https://stackoverflow.com/questions/25602405/in-robot-framework-what-is-the-difference-between-a-list-variable-and-a-scalar) – asprtrmp Oct 29 '19 at 08:03
  • @asprtrmp If you knew the names of the operators, then perhaps it would be a duplicate. However, this question (implicitly) asks what those names are, in addition to their differences. Anecdotally, a simple web search brought up this question, but not the one you linked. – TeckFudge Jan 17 '22 at 20:14

2 Answers2

2

The @ operator expects a list structure (similar to an array on classic programming languages).

Whenever you create a list or a dictionary, you assign that variable to a $ variable.

You can always access a list variable (@) or a dictionary variable (&) using the simple $ variable operator. That however will print the whole content of the variable.

For accessing items in a list or key/value pairs in a dictionary, you must use its corresponding operator. It looks like this:

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

And it'll work fine doing this:

Log    ${list_variable}
Log    ${dictionary_variable}

But for accessing its content as a data structure, you'll need to do this:

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

And so on

2

@ - Used to create list, & - used to create Dictionary, $ - used to create string/integer

@{list_variable}=    Create List    item1    item2    item3
log ${list_variable}     => when you have to access list, Need to use $ not @

Similar for Dictionary.

and for creating and accessing variable - use $

satish
  • 21
  • 3