如何在打印功能中调用此功能定义? [英] How can i call this function definiton inside a print function?
本文介绍了如何在打印功能中调用此功能定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在python中创建了此函数定义:
I created this function definition in python:
def random_person():
mylist = ["wounded priestress", "crying girl"]
return random.choice(mylist)
现在我想在我的代码中的打印函数中调用该函数:
Now I want to call that function in a print function in my code:
print("In the temple, you find a random_person().")
不幸的是,它不会导致我为随机函数选择的字符串.这就是我得到的:
Unfortunately, it does not result in the strings I have chosen for my random function. This is what I get:
In the temple, you find a random_person().
推荐答案
只是认为我会编译注释中列出的所有选项:)
Just thought I'd compile all the options I listed in the comments :)
print(f"In the temple, you find a {random_person()}.") # my personal favorite
print("In the temple, you find a", random_person(), ".")
print("In the temple, you find a {}.".format(random_person()))
print("In the temple, you find a %s." % random_person())
还有@@ Jean-Francois':
And @Jean-Francois' too:
print("In the temple, you find a "+random_person()+".")
这篇关于如何在打印功能中调用此功能定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文