关于3-7Python的字符串format第三个代码模板

来源:3-7 Python的字符串format

木麟

2025-04-15 11:47

我照着课程讲义打的第三个示例指定{}的名字w,c,b,i 的程序运行代码了一遍,报错信息如下

Traceback (most recent call last):
  File "index.py", line 7, in 
    result = template.format(w = world, c = china, b = beijing, i = imoooc)
NameError: name 'imoooc' is not defined


写回答 关注

1回答

  • qq_慕慕1036804
    4天前
    template = "Welcome to {w}, {c}, {b}, {i}"
    world = "World"
    china = "China"
    beijing = "Beijing"
    # 这里没有定义 imoooc 变量
    result = template.format(w = world, c = china, b = beijing, i = imoooc)
    print(result)


Python3 入门教程(新版)

python3入门教程,让你快速入门并能编写简单的Python程序

160340 学习 · 1111 问题

查看课程

相似问题