49

Python__02--转义字符

 2 years ago
source link: https://blog.51cto.com/husheng/5936577
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Table of Contents

1 转义字符

定义:

转义字符(Escape character),所有的ASCII码都可以用“\”加数字(一般是8进制数字)来表示。而python中定义了一些字母前加""来表示常见的那些不能显示的ASCII字符,如\t,\n等,就称为转义字符,因为后面的字符,都不是它本来的ASCII字符意思了。

一句话:就是在一些字符前加 “\” 使它具有其他意义。

1.1 使用方式

  1. \n:换行

  2. \t:水平制表符Tab,1-4个空格

  3. \r:回车

    将光标回开头

    print(‘hello\rworld’)

    输出world会将hello覆盖

  4. \b:退格

  5. \:输出反斜杠

  6. ':输出单引号

  7. ":输出双引号

  8. 不希望字符串中的转义字符起作用,就使用原字符,在字符前加r或R

    注意:末尾不能是一个\,可以是两个

    print(r'hellow\nworld\\')
    

1.2 运行结果

1.2.1 完整代码

print('hellow\nworld')
print("==============1===============")
print('hellow\tworld')
print("==============2===============")
print('helloooo\tworld')
print("==============3===============")
print('hello\bworld')
print("==============4===============")
print(r'hellow\nworld\\')

1.2.2 运行结果

Python__02--转义字符_转义字符

Recommend

  • 20

    byzhangxinxu from https://www.zhangxinxu.com/wordpress/?p=9770 本文欢迎分享与聚合,全文转载就不必了,尊重版权,圈子就这么大,若急用可以联系授权。...

  • 21
    • blogread.cn 4 years ago
    • Cache

    添加URL/HTML字符转义功能

    添加URL/HTML字符转义功能 浏览:1925次  出处信息        今天同事想用DataReport来展...

  • 13
    • abcdxyzk.github.io 4 years ago
    • Cache

    html中制表符(TAB)的转义字符

    html中制表符(TAB)的转义字符 - kk Blog —— 通用基础kk Blog —— 通用基础 date [-d @int|str] [+%s|"+%F %T"]

  • 12

    Python基础(9)–字符串的概述、创建与转义字符◎知识点◎脚本练习#!/usr/bin/env python3# -*- coding: utf-8 -*-"""

  • 12

    Gson JsonPrimitive 反转义字符转换 2021-12-04 后端给了一个这种格式的 Json 数据:{ "obj":"[ { \"Name\":\"小明\" }, { \"Name\":\"小白\" }, { \"Name\":\"小黑\" } ]" }

  • 9
    • www.veiking.cn 3 years ago
    • Cache

    最常用特殊符号转义字符表

    最常用特殊符号转义字符表_二师兄_Veiking百草园-知识点滴,日常分享 本文搜集整理的是最常用特殊符号转义字符,转义字符是很多程序语言、数据格式和通信协议的形式文法的一部分。转义序列通常有两种功能。第...

  • 9
    • www.veiking.cn 3 years ago
    • Cache

    希腊字母转义字符表

    希腊字母转义字符表_二师兄_Veiking百草园-知识点滴,日常分享 本文搜集整理的是希腊字母转义字符,转义字符是很多程序语言、数据格式和通信协议的形式文法的一部分。转义序列通常有两种功能。第一个是编码一...

  • 12
    • www.veiking.cn 3 years ago
    • Cache

    重要特殊标记转义字符表

    重要特殊标记转义字符表_二师兄_Veiking百草园-知识点滴,日常分享 本文搜集整理的是重要特殊标记转义字符,转义字符是很多程序语言、数据格式和通信协议的形式文法的一部分。转义序列通常有两种功能。第一个...

  • 13
    • www.veiking.cn 3 years ago
    • Cache

    特殊符号转义字符表

    特殊符号转义字符表_二师兄_Veiking百草园-知识点滴,日常分享 本文搜集整理的是特殊符号转义字符,转义字符是很多程序语言、数据格式和通信协议的形式文法的一部分。转义序列通常有两种功能。第一个是编码一...

  • 12
    • blog.51cto.com 3 years ago
    • Cache

    Python 转义字符、格式化字符

    Python 转义字符、格式化字符 精选 原创

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK