diff --git a/docs/user_docs/support/faq-kcl.md b/docs/user_docs/support/faq-kcl.md index c6f315f6..d6928510 100644 --- a/docs/user_docs/support/faq-kcl.md +++ b/docs/user_docs/support/faq-kcl.md @@ -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) +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/support/faq-kcl.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/support/faq-kcl.md index 3781cf99..b71735d2 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/support/faq-kcl.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/support/faq-kcl.md @@ -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) +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/support/faq-kcl.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/support/faq-kcl.md index 3781cf99..b71735d2 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/support/faq-kcl.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/support/faq-kcl.md @@ -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) +``` diff --git a/versioned_docs/version-0.7.0/user_docs/support/faq-kcl.md b/versioned_docs/version-0.7.0/user_docs/support/faq-kcl.md index c6f315f6..d6928510 100644 --- a/versioned_docs/version-0.7.0/user_docs/support/faq-kcl.md +++ b/versioned_docs/version-0.7.0/user_docs/support/faq-kcl.md @@ -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) +```