PYTHON
打开JUPTER NOTEBOOK,新建一个空白的PY文档。
# 如果字符串前面没有not,就在前面加not# 如果字符串前面有not,就返回原本的字符串我们首先定义一下条件作为示范。
def not_string(str): if 'not' in str: print(str) else: print ('not ' + str) print(not_string('we'))这里可以不需要用PRINT.
def not_string(str): if 'not' in str: return str else: return 'not ' + strprint(not_string('we'))直接用RETURN就可以了。
def not_string(str): if 'not' in str: return str else: return 'not ' + strprint(not_string('we are not'))但是我们想在有NOT的,但是NOT不在前面的字符串上加NOT,这种情况就不行了。
def not_string(str): if str[:3] == 'not': return str else: return 'not ' + str print(not_string('we are not'))print(not_string('we'))我们用数列来定义。
def not_string(str): if str[:3] == 'not' and len(str) > 3: return str else: return 'not ' + str print(not_string('we are not'))print(not_string('we'))这样来表达会比较严谨。
注意范围从0开始