저는 파이썬에서 새롭습니다.함수 안에있는 두 개의 벡터
내부에 두 개의 벡터가있는 함수를 만들고 싶습니다. 나는이
def twovectors((velocity1,length1),(velocity2,length2)):
같은 시도하지만,
SyntaxError: invalid syntax.
하시기 바랍니다 같은 메시지 오류가 도움이 필요합니다.
저는 파이썬에서 새롭습니다.함수 안에있는 두 개의 벡터
내부에 두 개의 벡터가있는 함수를 만들고 싶습니다. 나는이
def twovectors((velocity1,length1),(velocity2,length2)):
같은 시도하지만,
SyntaxError: invalid syntax.
하시기 바랍니다 같은 메시지 오류가 도움이 필요합니다.
. Python 언어 참조에서 Multiple Function Arguments 또는 8.6. Function definitions을 확인하십시오. 이 같은
시도 뭔가 :
def twovectors(vector1, vector2):
velocity1, length1 = vector1
velocity2, length2 = vector2
# Other code...
내가 제공 튜플 인수를 확장
tuple unpacking을 사용했다.
는이 방법으로 파이썬에서 함수를 작성 : 당신은 매개 변수로 함수 정의에 튜플을 넣을 수 없습니다
def twovectors(velocity1, velocity2):
# You can get the length of those vectors after you get inside the function
len1, len2 = len(velocity1), len(velocity2)
// Your code here
return whateveryouwantto