2013-12-08 39 views
-5

如果我有兩種方法:如何打印返回的元組的另一種方法

  1. 一個是改變一個stringtuple,並返回它的方法。
  2. 其他方法打印出返回的tuple

最後我該怎麼做?

輸入將類似於"12345 firstName lastName otherInfo"

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

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

您能否提供輸入和預期輸出? – Asterisk

+0

您是否嘗試過將參數傳遞給'printAsString'?你的'信息'功能已經有了一個參數,所以你知道它是如何工作的。 –

回答

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

恰當的[Python編碼風格](http://www.python.org/dev/peps/pep-0008/)的好例子。 – martineau

1

這將是

print ''.join(employeeInfo) 

但我的問題是,到底從哪裏傳來employeeInfo形式?

相關問題