Skip to content

Commit

Permalink
faq: add list element unpack to string ways
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Nov 29, 2023
1 parent 45afd2a commit e51b1bd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/user_docs/support/faq-kcl.md
Original file line number Diff line number Diff line change
Expand Up @@ -2339,3 +2339,16 @@ t_float: float = float(t_str) # you will get "t_float: 1.0"
```

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).

## 51. Is there an easy way to unpack a list into a string?

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:

```python
allowed = ["development", "staging", "production"]

schema Data:
environment: str
check:
environment in allowed, "environment must be one of {}".format(allowed)
```
Original file line number Diff line number Diff line change
Expand Up @@ -2353,3 +2353,16 @@ t_float: float = float(t_str) # 输出的 t_float 为一个浮点型 "t_float:
```

如果您想查看更多详细的关于KCL类型系统和类型转换的内容,您可以查阅 [KCL 内置类型](https://kcl-lang.io/docs/reference/lang/tour#built-in-types)[KCL 类型系统](https://kcl-lang.io/docs/reference/lang/tour#type-system)

## 51. 如何将列表类型的变量逐个解包到字符串中

KCL 的列表提供了内置的字符串格式化方法,我们可以使用 str 函数或者 str 变量的 format 函数完成此类功能,比如下面的代码

```python
allowed = ["development", "staging", "production"]

schema Data:
environment: str
check:
environment in allowed, "environment must be one of {}".format(allowed)
```
Original file line number Diff line number Diff line change
Expand Up @@ -2353,3 +2353,16 @@ t_float: float = float(t_str) # 输出的 t_float 为一个浮点型 "t_float:
```

如果您想查看更多详细的关于KCL类型系统和类型转换的内容,您可以查阅 [KCL 内置类型](https://kcl-lang.io/docs/reference/lang/tour#built-in-types)[KCL 类型系统](https://kcl-lang.io/docs/reference/lang/tour#type-system)

## 51. 如何将列表类型的变量逐个解包到字符串中

KCL 的列表提供了内置的字符串格式化方法,我们可以使用 str 函数或者 str 变量的 format 函数完成此类功能,比如下面的代码

```python
allowed = ["development", "staging", "production"]

schema Data:
environment: str
check:
environment in allowed, "environment must be one of {}".format(allowed)
```
13 changes: 13 additions & 0 deletions versioned_docs/version-0.7.0/user_docs/support/faq-kcl.md
Original file line number Diff line number Diff line change
Expand Up @@ -2339,3 +2339,16 @@ t_float: float = float(t_str) # you will get "t_float: 1.0"
```

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).

## 51. Is there an easy way to unpack a list into a string?

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:

```python
allowed = ["development", "staging", "production"]

schema Data:
environment: str
check:
environment in allowed, "environment must be one of {}".format(allowed)
```

0 comments on commit e51b1bd

Please sign in to comment.