---
title: "2024-04-25 13:05:59 UTC"
url: "https://versun.me/852"
markdown_url: "https://versun.me/852.md"
format: "note"
published: "2024-04-25T13:05:59.000Z"
updated: "2026-01-05T05:30:33.000Z"
collections:
  - "Blog"
site: "Versun"
---

# 2024-04-25 13:05:59 UTC

原来python的format函数是必需给所有的占位符赋值的，不能只赋值其中一个。  
比如下面的代码会报错，因为country没有赋值

```python
my_str = "My name is {name}, I'm from {country}"     
print( my_str.format(name='Versun') )     
```

所以如果对于用户输入的字符串，比如用于AI的提示词，用replace更合适些。
