python - 我们如何将多个字符串连接在一起?
问题描述
我正在尝试创建一个看起来像这样的字符串。
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'])
或这个 :
my_string = ', '.join(['place_id: ' + 'x', 'licence: ' + 'x', 'osm_type: ' + 'X', 'osm_id: ' + 'X', 'boundingbox: ' + 'X', 'lat: ' + 'X', 'lon: ' + 'X'])
很丑,但应该可以
推荐阅读
- php - 我如何从特定的多数组中仅获取八月的数据
- ios - Swift:重复字母变成字符串中的数字
- c# - 从节点列表中获取子节点的值,XML Xpath C#
- javascript - 系列工具提示中的 Echart 图标
- c - 多次重用原始套接字或创建新套接字
- ssis - 错误 Odatasource 编辑器 System.Net.HttpWebresponse
- angular - Angular 静态注入器错误 - 没有 API 提供者
- php - codeigniter 不返回 json/ajax 响应
- ios - UITableView 逐个单元格更改图像和标题位置
- javascript - 将元素添加到传递的 jQuery 选择器