2013-12-08 2 views
-5

에 반환 된 튜플을 인쇄하는 방법 :나는 두 가지 방법이 있다면 다른 방법

  1. 하나가 tuplestring을 변경하고 반환하는 방법입니다.
  2. 다른 방법으로는 tuple이 인쇄됩니다.

결국 어떻게해야합니까?

입력은 "12345 firstName lastName otherInfo"과 같을 것입니다.

def information(sentence): 
    splitUp = sentence.split(' ') 
    return sentence 

def printAsString(): 
    "".join(sentence) 
    print(sentence) 
+1

입력과 예상 출력을 제공 할 수 있습니까? – Asterisk

+0

'printAsString'에 인수를 전달하려고 시도 했습니까? 'information' 함수는 이미 인수를 취합니다. 그래서 어떻게 작동하는지 알 수 있습니다. –

답변

2

여기에 한 가지 방법이 있습니다. 그러나 당신의 목표는 무엇입니까? 이 코드는 무의미합니다 ...

def information(sentence): 
    '''Splits the sentence on space and returns it as tuple''' 
    split_up = tuple(sentence.split(' ')) 
    return split_up 

def print_as_string(): 
    '''Prints tuple as string''' 
    sentence = "welcome to SO dear friend" 
    print(" ".join(information(sentence))) 

if __name__ == "__main__": 
    print_as_string() 
+1

적절한 [파이썬 코딩 스타일] (http://www.python.org/dev/peps/pep-0008/)의 좋은 예. – martineau

1

이 될 것

print ''.join(employeeInfo) 

그러나 땅에 employeeInfo 양식을 온 않은 경우 제 질문은?