[英]KeyError: 'a' while writing a program in python
a=input('enter the name\n')
b=input('enter the age\n')
print('your name is {a} and your age is {b}'.format(a,b))
我在上面運行一段代碼,但在 python 中出現以下錯誤:
Traceback (most recent call last):
File "main.py", line 4, in <module>
print('your name is {a} and your age is {b}'.format(a,b))
KeyError: 'a'
您正在組合兩種不同的語法。 嘗試以下操作之一:
print('your name is {} and your age is {}'.format(a,b))
或者
print(f'your name is {a} and your age is {b}') # notice the f in the begining
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.