title | toc | date | top |
---|---|---|---|
Records |
true |
2017-12-30 |
3 |
try:
x2 = myDict['key2']
except KeyError as e:
print e.args[0]
print('.', end='')
r
is a prefix for string literals. This means, r"1\2\3\4" will not interpret \ as an escape when creating the string value, but keep \ as an actual character in the string. Thus, r"1\2\3\4" will have seven characters.
var = "1\2\3\4"
will interpret backslashes as escapes, create the string '1\x02\x03\x04'
(a four-character string), then assign this string to the variable var
.
import time
time.sleep(amount) #单位s
使用KeyboardInterrupt
捕获异常ref.
try:
# DO THINGS
except KeyboardInterrupt:
# quit
sys.exit()