我正在开发基于文本的游戏,到目前为止,我已经做到了:
class Map():
room1 = ('sampletext')
print(Map(room1))
但后来我得到一个错误:
Traceback (most recent call last):
File "C:/Users/Owner/Downloads/Text.py", line 3, in <module>
print(Map(room1))
NameError: name 'room1' is not defined
而且我不明白为什么不打印变量的字符串,因为我正在调用类,但是它说变量在代码中未被识别为变量。我需要反馈,以便完成游戏。
最佳答案
尝试这个:
class Map():
room1 = ('sampletext')
print(Map.room1)
输出:
sampletext
关于python - 类字符串和打印功能,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50730813/