{'屏幕尺寸': "15.6''", '处理器': 'i7-9750HF'}用python转换为json
时间: 2023-12-24 19:02:00 浏览: 19
你可以使用 `json` 模块来将Python字典转换为JSON格式。以下是一个示例代码:
```python
import json
data = {'屏幕尺寸': "15.6''", '处理器': 'i7-9750HF'}
json_data = json.dumps(data)
print(json_data)
```
这将输出转换后的JSON字符串:
```
{"屏幕尺寸": "15.6''", "处理器": "i7-9750HF"}
```
你可以将字典传递给 `json.dumps()` 函数,并使用 `print()` 打印转换后的JSON字符串。
相关问题
用正则匹配<div class="WordSection1" style="layout-grid:15.6pt;">中的style="layout-grid:15.6pt;"
可以使用以下正则表达式进行匹配:
```python
import re
text = '<div class="WordSection1" style="layout-grid:15.6pt;">'
pattern = r'style="[^"]+"'
match = re.search(pattern, text)
if match:
print(match.group(0))
else:
print("No match")
```
输出结果为:
```
style="layout-grid:15.6pt;"
```
用正则匹配<div class="WordSection1" style="layout-grid:15.6pt;">中WordSection1" 后的所有内容
可以使用以下正则表达式进行匹配:
```python
import re
text = '<div class="WordSection1" style="layout-grid:15.6pt;">'
pattern = r'WordSection1"[^>]*>(.*?)<'
match = re.search(pattern, text)
if match:
print(match.group(1))
else:
print("No match")
```
输出结果为:
```
style="layout-grid:15.6pt;"
```