我想知道如何检查Python中字符串是否以“ hello”开头。
在Bash中,我通常这样做:
if [[ "$string" =~ ^hello ]]; then
do something here
fi
如何在Python中实现相同的目标?
aString = "hello world"
aString.startswith("hello")
有关的更多信息startswith
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句