如何将多个字符串连接在一起?



我正在尝试创建一个看起来像这样的字符串。

my_string = ''.join('place_id': 'x', 'licence': 'x', 'osm_type': 'X', 'osm_id': 'X', 'boundingbox': 'X', 'lat': 'X', 'lon': 'X')

,或者:

my_string = str('place_id': 'x', 'licence': 'x', 'osm_type': 'X', 'osm_id': 'X', 'boundingbox': 'X', 'lat': 'X', 'lon': 'X')

我一直得到关于无效语法的错误。我认为是:字符导致了这个问题,但我不知道。谁能指出我的错误,因为我没看出来。

我期望的结果是这样的字符串:

'place_id': 231350287, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. osm.org/copyright', 'osm_type': 'way', 'osm_id': 701902497, 'boundingbox': ['41.4689704', '41.4693896', '-81.9377844', '-81.9371249'], 'lat': '41.46913635', 'lon': '-81.93749898507869'

不能将:直接放在join

我建议你这样做:

my_string = ', '.join(['place_id'+': '+'x', 'licence'+': '+'x', 'osm_type'+': '+'X', 'osm_id'+': '+'X', 'boundingbox'+': '+'X', 'lat'+': '+'X', 'lon'+': '+'X'])

或this:

my_string = ', '.join(['place_id: ' + 'x', 'licence: ' + 'x', 'osm_type: ' + 'X', 'osm_id: ' + 'X', 'boundingbox: ' + 'X', 'lat: ' + 'X', 'lon: ' + 'X'])

很丑,但应该可以用

最新更新