# -*- coding: cp936 -*-
#P44 3.1 基本字符串操作
#标准序列操作(索引、分片、乘法、判断成员资格、求长度、取最小值和最大值)适用于字符串
website = 'http://www.python.org'
website[-3:] = 'com' #字符串不可变,非法操作
raw_input("Press <enter>")
# -*- coding: cp936 -*-
#P44 3.2 字符串格式化:精简版
format = "Hello, %s. %s enough for ya?"
values = ('world', 'Hot')
print format % values
format = "Pi with three decimals: %.3f" # .3保留3位小数
from math import pi
print format % pi
#模板字符串
from string import Template
s = Template('$x, glorious $x!')
#substitute模板方法 会用传递进来的关键字参数foo替换字符串的$foo
print s.substitute(x='slurm')
#参数名x用大括号括起来,从而准确指明结尾,表示替换字段是单词的一部分
s = Template("It's ${x}tastic!")
print s.substitute(x='slurm')
#用两个$插入美元符号
s = Template("Make $$ selling $x!")
print s.substitute(x='slurm')
#除了 关键字参数 之外,还可以使用字典变量提供值、名称对
s = Template('A $thing must never $action.')
d = {}
d['thing'] = 'gentleman'
d['action'] = 'show his socks'
print s.substitute(d)
raw_input("Press <enter>")