Python笔记:1.27字符串_转义

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bq_cui/article/details/89887048
# -*- coding: utf-8 -*-
"""
Created on Mon May  6 16:40:56 2019

@author: Administrator
"""

a="let's go"
print(a)

b='"hello", lets go'
print(b)

b="'hello', lets go"
print(b)

b='hello,'"lets go"
print(b)

b='hello,'+"game over"
print(b)

b='hello,'*4
print(b)

#字符串中每一个字符都有索引号,从左至右从0开始,从右向左从-1开始
b='game over'
print(b[0], b[1], b[2], b[3])
print(b[-1], b[-2], b[-3], b[-4])

#转义字符
ch='C:\Program Files\nozilla Firefox\plugins'
print(ch)

#反转义
ch='C:\Program Files\\nozilla Firefox\plugins'
print(ch)

运行:

let's go
"hello", lets go
'hello', lets go
hello,lets go
hello,game over
hello,hello,hello,hello,
g a m e
r e v o
C:\Program Files
ozilla Firefox\plugins
C:\Program Files\nozilla Firefox\plugins

猜你喜欢

转载自blog.csdn.net/bq_cui/article/details/89887048