Function output removing symbols

Viewed 30

I need help with the output I'm getting in the function. I have pasted the code below:

def follower_data():
  random_lenght = int(random.randint(0,49))
  return data[(random_lenght)]['name'], data[(random_lenght)]['description'], data[(random_lenght)]['country']

data = follower_data()
print(f"Compare A: {data}" )

Output:

Compare A: ('Billie Eilish', 'Musician', 'United States')

But I want the output to be:

Compare A: Billie Eilish, Musician, United States
1 Answers

You return a tuple from the function you have to join function to convert it to a string.

Note: While Using join all the values in the list or tuple have types of string.

def follower_data():
  random_lenght = int(random.randint(0,49))
  return data[(random_lenght)]['name'], data[(random_lenght)]['description'], data[(random_lenght)]['country']

data = follower_data()
print(f"Compare A: {', '.join(data)}" )
OR Instead of returning data in the form of a tuple return it as a String using the join function
def follower_data():
  random_lenght = int(random.randint(0,49))
  return ', '.join(data[(random_lenght)]['name'], data[(random_lenght)]['description'], data[(random_lenght)]['country'])

data = follower_data()
print(f"Compare A: {data}" )
Related