求教:字符串单双引号问题。

来源:4-1 字符串的创建与拼接

慕妹7116552

2019-07-17 16:06:54

str1 = "I told my friend"she is beautiful""#这是老师演示错误的样子
str2 = 'I told my friend"she is beautiful"'#这是老师演示正确的样子
str3 = "I told my friend""she is beautiful"#这样写也不报错,请问可以吗?如果不可以为什么?

写回答

1回答

时间,

2019-07-17

同学,你好。同学的写法是将两个字符串拼接成一个。老师主要讲解的是当字符串中有单引号或双引号时,该字符串的写法。

str3 = "I told my friend""she is beautiful'"
str4 = "I told my friend 'she is beautiful'"
print(str3)   # I told my friendshe is beautiful'
print(str4)   # I told my friend 'she is beautiful'

如果我的回答解决了您的疑惑,请采纳!祝学习愉快~~~~

0

0 学习 · 8160 问题

查看课程