我想做的事:我想打印以下消息作为输出:嗨“别名”您的电话号码是“1234567890”,您的电子邮件 ID 是“foo@bar.foo”Python代码name= "alias"phone= "1234567890"email="foo@bar.foo"print("Hi " + name + " your phone number is " + phone + " and your email ID is " + email)这给了我以下输出:嗨,别名您的电话号码是 1234567890,您的电子邮件 ID 是 foo@bar.foo但是这里缺少双引号 (" ")。我试图解决这个问题:print("Hi " + \" name \" + " your phone number is " + \" phone \"+ " and your email ID is " + \" email \")
3 回答

慕尼黑的夜晚无繁华
TA贡献1864条经验 获得超6个赞
用 str.format
前任:
name= "alias"
phone= "1234567890"
email="foo@bar.foo"
result = 'Hi "{}" your phone number is {} and your email ID is {}'
print(result.format(name, phone, email))
或f 字符串(py3.6)
result = f'Hi "{name}" your phone number is {phone} and your email ID is {email}'
print(result)

幕布斯7119047
TA贡献1794条经验 获得超8个赞
将打印行替换为: print("Hi " + "\""+ name +"\"" + " your phone number is " + "\""+ phone +"\""+ " and your email ID is " +"\""+ email+ "\"")

catspeake
TA贡献1111条经验 获得超0个赞
使用两种类型的引号:
print('Hi "' + name + '" your phone number is "' + phone + '" and your email ID is "' + email + '"')
添加回答
举报
0/150
提交
取消