在main()中调用它时,有没有办法在cat()中改变单词cat to dog?
例如:
cut -c -5,9- <file>
cut --complement -c 6-8 <file>
答案 0 :(得分:2)
方法replace
返回原始字符串的副本,其中所有出现的子字符串'cat'都被'dog'替换。您可以将此新字符串分配给原始变量。
Refer Python Documentation for usage of replace
def notimportant2():
pass
def notimportant1():
pass
def string():
return ["This cat was scared."]
def contentList(skip_name=''):
functions = [notimportant1, notimportant2, string]
for f in functions:
if f.__name__ != skip_name:
f()
def main():
contentList('notimportant2')
for words in string():
words=words.replace("cat", "dog")
print(words)
main()