版权所有 (C) 2009 Microsoft Corporation。保留所有权利。
PS D:\> python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (
AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> round(1.7333)
2.0
>>> my_age=35 #not a lie
>>> my_height=74 #inches
>>> my_weight=180 #lbs
>>> print "If I add %d,%d, and %d I get %d." %(
... my_age,my_height,my_weight,my_age+my_height+my_weight)
If I add 35,74, and 180 I get 289.
>>> my_teeth='white'
>>> print "His teeth are usually %s depending on the coffee." %my_teeth
His teeth are usually white depending on the coffee.
>>> x="There are %d types of people." %10
>>> print x
There are 10 types of people.
>>> binary="binary"
>>> do_not="don't"
>>>
>>> y="Those who know %s and those who %s." %(binary,do_not)
>>>
>>> print y
Those who know binary and those who don't.
>>> print "I said: %r." %x
I said: 'There are 10 types of people.'.
>>> print "I also said:'%s'." %y
I also said:'Those who know binary and those who don't.'.
>>>
>>>
>>>
>>> hilarious=False
>>>
>>> joke_evaluation="Isn't that joke so funnny?! %r"
>>>
>>> print joke_evaluation % hilarious
Isn't that joke so funnny?! False
>>>
>>>
>>> w="This is the left side of ..."
>>> e="a string with a right side."
>>>
>>> print w+e
This is the left side of ...a string with a right side.
>>>
>>> print "I said: %r." %x
I said: 'There are 10 types of people.'.
>>>
>>>
>>> x = "There are %d types of people." % 10
>>>
>>> print "I also said: '%s'." % x
I also said: 'There are 10 types of people.'.
>>> print "I said: %r." %x
I said: 'There are 10 types of people.'.
>>> print "I said: %s." %x
I said: There are 10 types of people..
>>>
>>> x = "There are %d types of people." % 10
>>>
>>> print "I also said: '%s'." % x
I also said: 'There are 10 types of people.'.
>>> print "I said: %r." %x
I said: 'There are 10 types of people.'.
>>> print "I said: %s." %x
I said: There are 10 types of people..
>>> x = "There are %s types of people." % 10
>>> print x
There are 10 types of people.
>>> print "I said: %s." %x
I said: There are 10 types of people..
>>> x = "There are %d types of people." % x
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: %d format: a number is required, not str
>>>
>>>
>>> print "I said: %s." %a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>> print "I said: %s." %3
I said: 3.
>>> x = "There are %d types of people." % b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
>>> x = "There are %d types of people." % 3
>>> print x
There are 3 types of people.
>>>