字符串
# !coding=utf-8#
'''
字符串:单引号或双引号括起来的任意文本
‘abc’
"def"
字符串不可变
'''
# 创建字符串
str1 = "gxd is a good man"
str2 = 'gxd ia a nice man'
str5 = "sunck"
'''
字符串运算
'''
str6 = 'gxd'
str7 = 'is a good man'
str8 = str6 + str7
print str6, str7, str8
print(id(str6), id(str7), id(str8), id('gxd'))
# 输出重复字符串
str9 = 'good'
print str9 * 3
# 通过索引下标查找字符串中的字符,从0开始
str11 = u'g我d is a good man'
print str11[1]
# str11[1]='a' 会报错的
# 截取字符串中的一部分 从0开始,包前不包后
str13 = '0123456789'
str15 = str13[4:10]
print 'str15=', str15
# 从头截取
str16 = str13[:5]
print 'str16=', str16
# 截取到最后
str17 = str13[5:]
print 'str17=', str17
# in 和 not in
print 'good' in str1
print 'good1' in str1
print 'good1' not in str1
# '''
# 格式化输出,占位符 %d:整数
# %f:浮点数
# %s:字符串
# %.3f:精确到小数点后三位,四舍五入
# 转义符'\ ' \n :换行符,只是表示一个字节
#
# '''
str19 = 'gxd is a nice man!'
num1 = 10
f=10.22125
print('num1 = %d,\nstr19 = %s\nf=%.3f' % (num1, str19,f))
print('gxd is \\n a good man!')
#
print('Tom is a \'good\' man!')
print("Tom is a \"good\" man!")
#如果字符串内有多个换行,
print('''good
nice
handsome''')
#\t
print('good\tman')
#r:取消转移符:用r表示内部字符串不转义
print(r'\\\t\\t\\')