高 = 20
宽 = 15
print(高 * 宽) #300
直接用变量显示结果
a = 5
b = 6.5
c = a*b
c
#显示结果为32.5
再增加几行代码
a = 5
b = 6.5
c = a*b
c
d = 12
d
#显示结果12
使用print()显示结果
a = 5
b = 6.5
c = a*b
print(c)
#显示结果为32.5
a = 5
b = 6.5
c = a*b
print(c)
d = 12
print(d)
#显示结果
32.5
12
结论:直接使用变量来显示结果,就只会显示最后一处变量的值。print()则会显示每一处变量的值。
双引号里可以包含单引号,或者单引号里包含双引号
"this is a 'red' apple "
'his is a "red" apple '
需要显示一些特殊字符就需要用 进行转义
'I don't like it'
""Ok", he replied "
#结果 "Ok", he replied
print('d:dataresource')
#结果 esource
print('d:dataresource')
#结果 d:dataresource
注意,在字符串中,必须一起使用,否则就会发生错误
如果不行这么复杂,可以用源字符串,即在字符串前加一个字符r
print(r'd:dataresource')
#结果 d:dataresource
当然在源字符串中,结尾处也一样不能单独加一个 ,会报错。
print('''
item one
item two
item three
''')
#结果
item one
item two
item three
如果想让某一行与下一行显示在一行中,可以在这一行结尾加一个
print('''
item one
item two
item three
''')
#结果
item one item two
item three
"one" * 3
3 * 'one'
#结果都是 oneoneone
str = ("Python is a programming language that lets you work quickly"
"and integrate systems more effectively.")
str
#结果 'Python is a programming language that lets you work quicklyand integrate systems more effectively.'
str = 'python'
str[1] #y
str[-1] #n
str[-3] #h
str[1:3] #yt
str[]:2 #py
页面更新:2024-02-28
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号