问答详情
源自:3-7 Python的字符串format

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

我照着课程讲义打的第三个示例指定{}的名字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


提问者:木麟 2025-04-15 11:47

个回答

  • 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)