Title: concatenating string with tuples in python
Tags: python
Question: def print_distance(p1, p2):
dist = (((p2[0]-p1[0])**2)+((p2[1]-p1[1])**2))**0.5
d = print("{0:.2f}".format(dist))
result = ("Distance between ", ','.join(p1) ," and ", ','.join(p2) ," is "+ d)
return result
print_distance((0,1),(-1,-2))
TypeError: sequence item 0: expected str instance, int found
I couldn't figure it out the output "Distance between (0, 1) and (-1, -2) is 3.16" I am beginner to this thing. Help me.
Comment: you are trhing to use str.join to join your ints. str.join can only join strings.

Here is the accepted answer: your tuple contains ints so you cant join them with str.join. if you wanted to do that you would need to convert them first to str's. however to get the output you mentioned you can just use an fstring
def print_distance(p1, p2):
dist = (((p2[0]-p1[0])**2)+((p2[1]-p1[1])**2))**0.5
print(f"Distance between {p1} and {p2} is {dist:.2f}")
print_distance((0,1),(-1,-2))
OUTPUT
Distance between (0, 1) and (-1, -2) is 3.16

Here is another answer: result = ("Distance between ", ','.join(p1) ," and ", ','.join(p2) ," is "+ d)
this is line is just a bit of a mess maybe try using format the way you did elsewhere
result = "Distance between {p1} and {p2} is {d}".format(p1, p2, d)
I'd like to give you more context but the gist of it is you are using join incorrectly.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:12/25/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python>', 'Title': 'concatenating string with tuples in python', 'ViewCount': 65, 'id': 59480607, 'user_AboutMe': None, 'user_AccountId': 7063523.0, 'user_DisplayName': 'Oculus', 'user_Reputation': 33.0, 'user_Views': 5.0, 'user_id': 5407755.0}}