上一篇:Python3基础语法
上篇笔记提到过变量,它可以存储值。
a = "One Sweet Orange"
b = 123
print(a)
print(b)
输出
One Sweet Orange
123
上面的示例中,a,b是变量,对应存储的值是字符串 "One Sweet Orange"和整数123。
Python数字类型分为四种:整数、布尔数、浮点数、复数。
"I can't believe it!"
'"STOP!",he said.'
"""This is my favorite book,
what about you?"""
IN:
print('This is my favorite book,\nwhat about you?')
OUT:
This is my favorite book,
what about you?
IN:
print(r'This is my favorite book,\nwhat about you?')
OUT:
This is my favorite book,\nwhat about you?
IN:
print('one'+' sweet '+'orange')
OUT:
one sweet orange
IN:
print('orange '*3)
OUT:
orange orange orange
IN:
a = 'This is my favorite book, what about you?'
print(a[0]) # 打印第1个字符
print(a[-1]) # 打印最后1个字符
OUT:
T
?
IN:
a = 'This is my favorite book, what about you?'
print(a[0:9:1]) # 前9个字符,区间[0,9)前开后闭,步长取1。
print(a[0:9:2]) # 前9个字符,区间[0,9)前开后闭,步长取2。
print(a[0:9:3]) # 前9个字符,区间[0,9)前开后闭,步长取3。
OUT:
This is m
Ti sm
Tss