使用函数参数创建字符串参数

时间:2020-02-06 20:55:28

标签: python python-3.x string pyspark graphframes

我正在尝试创建一个函数,该函数将允许用户使用.bfs方法在Graphframe中执行广度优先搜索。函数示例如下:

    Graphframe.bfs("name = 'Esther'", "relationship = 'friend'")

我想要一个功能来工作:

    def friendZone(person, affiliation):
         Graphframe.bfs("name = 'person'", "relationship = 'affiliation'")

我尝试使用concat方法,例如:

     '"' + "name='" + person + "'" + '"'

,但这没有用。我也尝试使用

'"name={}"'.format(person).  

请帮助?

1 个答案:

答案 0 :(得分:1)

您可以使用f弦

def friendZone(person, affiliation):
         Graphframe.bfs(f"name = {person}", "relationship = {affiliation}")