From 6eca023e08a20ff8952ec40971d5e36d01b79edf Mon Sep 17 00:00:00 2001 From: Peefy Date: Wed, 6 Nov 2024 10:19:20 +0800 Subject: [PATCH] docs: add isnullish function faq documents Signed-off-by: Peefy --- docs/user_docs/support/faq-kcl.md | 10 ++++++++++ .../current/user_docs/support/faq-kcl.md | 10 ++++++++++ .../version-0.10/user_docs/support/faq-kcl.md | 10 ++++++++++ .../version-0.10/user_docs/support/faq-kcl.md | 10 ++++++++++ 4 files changed, 40 insertions(+) diff --git a/docs/user_docs/support/faq-kcl.md b/docs/user_docs/support/faq-kcl.md index 60aa3eed..d23b894e 100644 --- a/docs/user_docs/support/faq-kcl.md +++ b/docs/user_docs/support/faq-kcl.md @@ -482,6 +482,16 @@ isEmptyList = bool(_emptyList) isEmptyDict = bool(_emptyDict) ``` +In addition, if we want to determine that a variable is only `None`/`Undefined` and not empty, we can use the following expression or the built-in function `isnullish()` + +```python +a = None +_emptyList = [] +isEmptyList = bool(_emptyList) +isNullishList1 = _emptyList not in [None, Undefined] +isNullishList2 = isnullish(_emptyList) +``` + ## 12. How to concatenate strings, format strings, check string prefixes and suffixes and replace string content? - The `+` operator can be used to concatenate two strings in KCL 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 d02820d5..6a03ccf9 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 @@ -484,6 +484,16 @@ isEmptyList = bool(_emptyList) isEmptyDict = bool(_emptyDict) ``` +此外,如果我们想要判断一个变量仅为 `None`/`Undefined`,而不为空,则可以使用下面的表达式或者 `isnullish()` 内置函数 + +```python +a = None +_emptyList = [] +isEmptyList = bool(_emptyList) +isNullishList1 = _emptyList not in [None, Undefined] +isNullishList2 = isnullish(_emptyList) +``` + ## 12. 字符串怎样拼接、怎样格式化字符串、怎样检查字符串前缀、后缀?怎样替换字符串内容? - KCL 中可以使用 `+` 运算符连接两个字符串 diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.10/user_docs/support/faq-kcl.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.10/user_docs/support/faq-kcl.md index d02820d5..6a03ccf9 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.10/user_docs/support/faq-kcl.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.10/user_docs/support/faq-kcl.md @@ -484,6 +484,16 @@ isEmptyList = bool(_emptyList) isEmptyDict = bool(_emptyDict) ``` +此外,如果我们想要判断一个变量仅为 `None`/`Undefined`,而不为空,则可以使用下面的表达式或者 `isnullish()` 内置函数 + +```python +a = None +_emptyList = [] +isEmptyList = bool(_emptyList) +isNullishList1 = _emptyList not in [None, Undefined] +isNullishList2 = isnullish(_emptyList) +``` + ## 12. 字符串怎样拼接、怎样格式化字符串、怎样检查字符串前缀、后缀?怎样替换字符串内容? - KCL 中可以使用 `+` 运算符连接两个字符串 diff --git a/versioned_docs/version-0.10/user_docs/support/faq-kcl.md b/versioned_docs/version-0.10/user_docs/support/faq-kcl.md index 60aa3eed..d23b894e 100644 --- a/versioned_docs/version-0.10/user_docs/support/faq-kcl.md +++ b/versioned_docs/version-0.10/user_docs/support/faq-kcl.md @@ -482,6 +482,16 @@ isEmptyList = bool(_emptyList) isEmptyDict = bool(_emptyDict) ``` +In addition, if we want to determine that a variable is only `None`/`Undefined` and not empty, we can use the following expression or the built-in function `isnullish()` + +```python +a = None +_emptyList = [] +isEmptyList = bool(_emptyList) +isNullishList1 = _emptyList not in [None, Undefined] +isNullishList2 = isnullish(_emptyList) +``` + ## 12. How to concatenate strings, format strings, check string prefixes and suffixes and replace string content? - The `+` operator can be used to concatenate two strings in KCL