You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基础编程题:实现带not前缀判断的字符串处理功能

Python实现not_string函数

直接调用字符串内置的startswith()方法判断前缀即可,不需要额外处理短字符串的边界情况,该方法天然兼容长度小于3的入参:

def not_string(s):
    if s.startswith("not"):
        return s
    return "not " + s

测试验证

对应给定示例的测试结果完全符合要求:

  • not_string('candy') → 'not candy'
  • not_string('x') → 'not x'
  • not_string('not bad') → 'not bad'

内容的提问来源于stack exchange,提问作者Farjanul Nayem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.16 02:36:04