Discuss / Python / 关于变量的语法

关于变量的语法

Topic source

落寞斑马

#1 Created at ... [Delete] [Delete and Lock User]

总感觉这变量的语法有些奇怪,为何不把字符串存在 input() 这个空格里,而是要换行存入,和print的语法逻辑完全变了

name = input() print('hello,', name) 你是说的这段代码吗? 比如说一个注册功能,你无法知晓用户是如何进行数据填写的,通过利用input函数来获取用户的输入,然后在执行print来打印输出,我是这么理解的。

我的为什么是这样的,不对,而且输入一个print(‘hello,name’),运行.py 的时候还是hello world,请指导!谢谢! C:\Users\Zyp>python Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

name=input('please enter your name') please enter your name print('hello,'name) File "<stdin>", line 1 print('hello,'name) ^ SyntaxError: invalid syntax

@乔巴的鼻子1711 依据编译器报错,你需要在print()函数中字符串与变量之间加入“,”分隔符


  • 1

Reply