[英]Python: Print results of a parsing function in the function itself, or have the function return the result and print it an external calling function?
[英]how to print results of function as the result of a input function?
这个问题听起来可能很愚蠢,但我认为它非常简单。
所以我有一个叫做
def print_location_summary(location_name):
and it dose its thing. and prints out a results.
我现在有另一个功能,要求用户输入:
def main():
"""Prompts for user to input a location name"""
location_name = input("Please enter location name:")
(NEED A CODE HERE)
main()
我如何将第一个功能的结果打印为第二个功能的结果
例如:
def main():
"""Prompts for user to input a location name"""
location_name = input("Please enter location name:")
print(def print_location_summary(location_name))
main()
但这巧妙地行不通。 请帮助:)如果您需要更多信息,请告诉我。
我不确定100%知道您的问题。 但是,除了具有要打印的功能外,我还可以让该功能返回您要打印的信息。 即
def get_location_summary(location_name):
output = "This is my output stored in a variable. My location is: " + location_name
""" return the output to the caller """
return output
def main():
"""Prompts for user input to a location name"""
location_name = input('Please enter a location name: ')
"""print below calls the function which returns the value that was stored in the output variable inside get_location_summary. This value is then printed"""
print(get_location_summary(location_name))
if __name__ == "__main__":
main()
对不起大家。 这是一个愚蠢的问题。 这实际上有效。
def main():
"""Prompts for user to input a location name"""
location_name = input("Please enter location name:")
print ("")
print (print_sorted_stock_summary(location_name))
main()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.