Skip to content

docs: add hyphen attribute name in language tour documents #372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/reference/lang/tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ data = {
} # {"key1": "value1", "key2": "value2"}
```

We can ignore the key quotation marks when we writing simple literals on the key.
We can ignore the attribute quotation marks when we writing simple literals on the key.

```python
data = {
Expand All @@ -613,6 +613,15 @@ data = {
} # {"key1": "value1", "key2": "value2"}
```

Note that when there is `-`, `.` and other hyphens in the attribute, we must use quotation marks.

```python
data = {
"config.dot.attr" = "value1" # Note we use `"config.dot.attr"` instead of `config.dot.attr` here.
"config-hyphen-attr" = "value2" # Note we use `"config-hyphen-attr"` instead of `config-hyphen-attr` here.
}
```

In addition, the **config selector expressions** can be used to init a dict instance with nested keys.

```python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,15 @@ data = {
} # {"key1": "value1", "key2": "value2"}
```

请注意,当属性中存在 `-` 和 `.` 等其他连字符时,我们必须使用引号。

```python
data = {
"config.dot.attr" = "value1" # Note we use `"config.dot.attr"` instead of `config.dot.attr` here.
"config-hyphen-attr" = "value2" # Note we use `"config-hyphen-attr"` instead of `config-hyphen-attr` here.
}
```

此外,**选择表达式**可以用于定义包含嵌套键 dict 实例。

```python
Expand Down
Loading