目录:
一:字面常量
二:变量
一:字面常量
1 print ('i l'ove've fishc.com')
SyntaxError: invalid syntax
→
#print ('i l"ove" fishc.com') or print ("i l'ove' fishc.com")
2TypeError: cannot concatenate 'str' and 'int' objects
→只有提前把num转换为字符串类型,可以使用bytes函数把int型转换为string型。
print ('123:' + bytes(name))
3Format 使用
print('{name} wrote {book}'.format(name= 'www'),book = 'jjjj') KeyError: 'book'
→
print('{name} wrote {book}'.format(name= 'www',book = 'jjjj'))
4print("This is the first sentence.
This is the second sentence
SyntaxError: EOL while scanning string literal
→
print("This is the first sentence.\
this is the second sentence")
二:变量
1s = '''this is a multi-line string.
this is the second line.'''
print(s)
s = '''this is a multi-line string.
this is the second line.'''
print(s)
输入这种 居然不算重复
2所谓物理行(Physical Line)是你在编写程序时 你所看到 的内容。
所谓逻辑行(Logical Line)是 Python 所看到 的单个语句
3 放置在一起的语句必须拥有相同的缩进。每一组这样的语句被称为 块(block)
4 print(i)
^
IndentationError: unexpected indent
→ 注意缩进