字符串

1. 字符串中使用'或"时的转译\

print(Today\'s weather is good')

2. 换行符\n

print('How are you \nI\'m fine')

3. 索引

'hello_shiyanlou' 编号0对应第一个字符h,1对应第二个字符e

str = 'hello_shiyanlou'

str[0]  #获取第一个字符 h

str[1]   #获取第二个字符 e

str[-1] #获取倒数第一个字符 u

str[-2] #获取倒数第二个字符 o

4. 格式化字符串 format

name = 'shi'

age = 20 

print('我叫{},今年{}岁了'.format(name, age)) # 格式化字符串

print('{:.3f}'.format(3.14159))

 

posted @ 2020-07-13 18:10  shizy6  阅读(48)  评论(0)    收藏  举报