美文网首页
python中的转义

python中的转义

作者: ljZhang416 | 来源:发表于2019-05-29 16:56 被阅读0次

    当需要在字符串中使用特殊字符时,我们需要用到python中的反斜杠()转义字符。下面介绍几个餐饮的转义符:
    \:反斜杠符号

    print('2.Amy got up late, and she said "I miss the breakfast,this monring"')#\\是单斜杠
    
    输出结果如下: image.png

    \':单引号

    print('4.Amy got up late, and she said \'I miss the breakfast,this monring\'')#\\是单引号
    
    输出结果如下: image.png

    \":双引号

    print("3.Amy got up late, and she said \"I miss the breakfast,this monring\"")#\"是双引号
    
    输出结果如下: image.png

    \a:响铃

    print('5.Amy got up late, \aand she said "I miss the breakfast,this monring"')#\a是响铃符
    
    输出结果如下(会有响铃声): image.png

    \b:退格(Backspace)

    print('6.Amy got up late, \band she said "I miss the breakfast,this monring"')#\b是退格符
    
    输出结果如下: image.png

    \n:换行

    print('8.Amy got up late, \nand she said "I miss the breakfast,this monring"')#\n是换行符
    
    输出结果如下:

    \v:纵向制表符

    print('10.Amy got up late, \vand she said "I miss the breakfast,this monring"')#\v是垂直制表符
    
    输出结果如下: image.png

    \t:横向制表符

    print('\t1.Amy got up late, and she said "I miss the breakfast,this monring"')#\t是tab
    
    输出结果如下: image.png

    \r:回车

    print('9.Amy got up late, \rand she said "I miss the breakfast,this monring"')#\r是回车
    
    输出结果如下: image.png

    \f:换页

    print('7.Amy got up late, \fand she said "I miss the breakfast,this monring"')#\f是换页
    
    输出结果如下: image.png

    \xyy:十六进制数,yy代表的字符,例如:\x0a代表换行
    \other:其它的字符以普通格式输出

    相关文章

      网友评论

          本文标题:python中的转义

          本文链接:https://www.haomeiwen.com/subject/hjgytctx.html