如何在另一种方法中打印返回的元组

时间:2013-12-08 10:48:29

标签: python return tuples

如果我有两种方法:

  1. 一种方法可将string更改为tuple并将其返回。
  2. 其他方法打印出tuple返回的内容。
  3. 最后我该怎么做?

    输入类似于"12345 firstName lastName otherInfo"

    def information(sentence):
        splitUp = sentence.split(' ')
        return sentence
    
    def printAsString():
        "".join(sentence)
        print(sentence)
    

2 个答案:

答案 0 :(得分: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 :(得分:1)

这将是

print ''.join(employeeInfo)

但我的问题是employeeInfo到底在哪里形成?

相关问题