Skip to content

Commit e51b1bd

Browse files
committed
faq: add list element unpack to string ways
Signed-off-by: peefy <xpf6677@163.com>
1 parent 45afd2a commit e51b1bd

File tree

4 files changed

+52
-0
lines changed
  • docs/user_docs/support
  • i18n/zh-CN/docusaurus-plugin-content-docs
  • versioned_docs/version-0.7.0/user_docs/support

4 files changed

+52
-0
lines changed

docs/user_docs/support/faq-kcl.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,3 +2339,16 @@ t_float: float = float(t_str) # you will get "t_float: 1.0"
23392339
```
23402340

23412341
For more information about type conversion, see [KCL Builtin Types](https://kcl-lang.io/docs/reference/lang/tour#built-in-types) and [KCL Type System](https://kcl-lang.io/docs/reference/lang/tour#type-system).
2342+
2343+
## 51. Is there an easy way to unpack a list into a string?
2344+
2345+
The KCL list provides built-in string formatting methods, which can be achieved using the str function or the format function of the str variable, such as the following code:
2346+
2347+
```python
2348+
allowed = ["development", "staging", "production"]
2349+
2350+
schema Data:
2351+
environment: str
2352+
check:
2353+
environment in allowed, "environment must be one of {}".format(allowed)
2354+
```

i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/support/faq-kcl.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,3 +2353,16 @@ t_float: float = float(t_str) # 输出的 t_float 为一个浮点型 "t_float:
23532353
```
23542354

23552355
如果您想查看更多详细的关于KCL类型系统和类型转换的内容,您可以查阅 [KCL 内置类型](https://kcl-lang.io/docs/reference/lang/tour#built-in-types)[KCL 类型系统](https://kcl-lang.io/docs/reference/lang/tour#type-system)
2356+
2357+
## 51. 如何将列表类型的变量逐个解包到字符串中
2358+
2359+
KCL 的列表提供了内置的字符串格式化方法,我们可以使用 str 函数或者 str 变量的 format 函数完成此类功能,比如下面的代码
2360+
2361+
```python
2362+
allowed = ["development", "staging", "production"]
2363+
2364+
schema Data:
2365+
environment: str
2366+
check:
2367+
environment in allowed, "environment must be one of {}".format(allowed)
2368+
```

i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/support/faq-kcl.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,3 +2353,16 @@ t_float: float = float(t_str) # 输出的 t_float 为一个浮点型 "t_float:
23532353
```
23542354

23552355
如果您想查看更多详细的关于KCL类型系统和类型转换的内容,您可以查阅 [KCL 内置类型](https://kcl-lang.io/docs/reference/lang/tour#built-in-types)[KCL 类型系统](https://kcl-lang.io/docs/reference/lang/tour#type-system)
2356+
2357+
## 51. 如何将列表类型的变量逐个解包到字符串中
2358+
2359+
KCL 的列表提供了内置的字符串格式化方法,我们可以使用 str 函数或者 str 变量的 format 函数完成此类功能,比如下面的代码
2360+
2361+
```python
2362+
allowed = ["development", "staging", "production"]
2363+
2364+
schema Data:
2365+
environment: str
2366+
check:
2367+
environment in allowed, "environment must be one of {}".format(allowed)
2368+
```

versioned_docs/version-0.7.0/user_docs/support/faq-kcl.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,3 +2339,16 @@ t_float: float = float(t_str) # you will get "t_float: 1.0"
23392339
```
23402340

23412341
For more information about type conversion, see [KCL Builtin Types](https://kcl-lang.io/docs/reference/lang/tour#built-in-types) and [KCL Type System](https://kcl-lang.io/docs/reference/lang/tour#type-system).
2342+
2343+
## 51. Is there an easy way to unpack a list into a string?
2344+
2345+
The KCL list provides built-in string formatting methods, which can be achieved using the str function or the format function of the str variable, such as the following code:
2346+
2347+
```python
2348+
allowed = ["development", "staging", "production"]
2349+
2350+
schema Data:
2351+
environment: str
2352+
check:
2353+
environment in allowed, "environment must be one of {}".format(allowed)
2354+
```

0 commit comments

Comments
 (0)