-3
문제점 : 함수 위치를 입력/정수로 find_second 함수로 변환/사용하는 방법을 모르겠다.파이썬에서 함수를 int로 변환하는 방법은 무엇입니까? 아니면 가능한가?
코드
# Define a procedure, find_second, that takes
# two strings as its inputs: a search string
# and a target string. It should return a
# number that is the position of the second
# occurrence of the target string in the
# search string.
def position (search_string, target):
position_target = search_string.find(target)
return int(position_target)
def find_second (search_string, second_target):
return search_string.find(second_target, position+1)
danton = "De l'audace, encore de l'audace, toujours de l'audace"
print find_second(danton, 'audace')`
오류 메시지가 :
Traceback (most recent call last):
File "vm_main.py", line 33, in <module>
import main
File "/tmp/vmuser_laavqhjazh/main.py", line 19, in <module>
print find_second(danton, 'audace')
File "/tmp/vmuser_laavqhjazh/main.py", line 13, in find_second
return search_string.find(second_target, position+1)
TypeError: unsupported operand type(s) for +: 'function' and 'int'
아마도 서로 다른 인수를 사용하여 position (search_string, second_target) + 1을 원하십니까? – chepner
실제로 * 함수를 호출해야합니다. – kindall
@chepner 감사합니다. :피 –