>>> print('You must','do it','quickly');
>>> print ('100+200=',100+200);
>>> name=input('Please enter your name:');
Please enter your name:Amy
>>> print('Hello,',name)
Hello, Amy
print('I \'m Ok')
>>> print('\\\t\\')
\ \
>>> print(r'\\\t\\')
\\\t\\
>>> print('''line1
... line2
... line3''')
line1
line2
line3
>>> 9 / 3
3.0
>>> 10 // 3
3
>>> 10 % 3
1
输出以下结果:
n = 123
f = 456.789
s1 = ‘Hello, world’
s2 = ‘Hello, \’Adam\”
s3 = r’Hello, “Bart”’
s4 = r”’Hello,
Lisa!”’
>>> print('n=',123)
>>> print('f=',456.789)
>>> print('s1=',"'Hello,world'")
>>> print('S2=',"'Hello,\\'Adam\\''")
>>> print('S3=',"r'Hello,\"Bart\"'")
>>> print('s4 =', "r'''Hello,\n Lisa!'''")
>>> print('Hello,%s'%'world')
>>> print('Hi,%s,you have $%d'%('Amy',100000))
>>> '%2d-%02d' % (3, 1)
' 3-01'
>>> '%.2f' % 3.1415926
'3.14'
小明的成绩从去年的72分提升到了今年的85分,请计算小明成绩提升的百分点,并用字符串格式化显示出’xx.x%’,只保留小数点后1位:
>>> s1=72
>>> s2=95
>>> r=(s2-s1)/s1*100
>>> print('%.1f %%' % r)
31.9 %