检查字符串是否以 XXXX 开头 [英] Checking whether a string starts with XXXX
本文介绍了检查字符串是否以 XXXX 开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何在 Python 中检查字符串是否以hello"开头.
I would like to know how to check whether a string starts with "hello" in Python.
在 Bash 中我通常这样做:
In Bash I usually do:
if [[ "$string" =~ ^hello ]]; then
do something here
fi
我如何在 Python 中实现相同的目标?
How do I achieve the same in Python?
推荐答案
aString = "hello world"
aString.startswith("hello")
关于startswith
.
这篇关于检查字符串是否以 XXXX 开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文