背景

我们经常需要使用raw string,在应用过程中,比如要使字符串中带一些转义字符或者其他的一些符号,我们就需要保持我们的字符成为raw string.

实例

输入

s = 'fadfafa\nhello'
s1 = r'fadfafa\nhello'
print("s is: ", s, sep='\n')
print("s1 is: ", s1, sep='\n')
a = repr(s)[1:-1]
print("a is: ", a, sep='\n')

输出

s is:
fadfafa
hello
s1 is:
fadfafa\nhello
a is:
fadfafa\nhello

通过上面的实例我们可以知道,我们想要获得raw string 可以通过在字符串前面加入r来装换,如果是字符串变量的话,我们可以通过repr来操作

python中的raw string的使用的更多相关文章

  1. C++11中的raw string literals

    作为一名C++书看得少得可怜的新手,我一直没有勇气去系统地学习一下C++ 11添加的新特性.不过,平日里逛论坛,阅读大犇们的博客,倒是了解了一些.比如,这个帖子: 如何绕过g++ 4.8.1那个不能在 ...

  2. python 中datetime 和 string 转换

    dt = datetime.datetime.strptime(string_date, fmt) fmt 的格式说明如下: https://docs.python.org/2/library/dat ...

  3. python中的raw字符串

    在正则表达式的字符串前面加上r表示这个是一个raw字符串,只以正则表达式的元字符进行解析,不用理会ascii的特殊字符.

  4. python中datetime与string的相互转换

    >>> import datetime >>> value = '2016-10-30 01:48:31' >>> datetime.strpti ...

  5. java和python中的string和int数据类型的转换

    未经允许,禁止转载!!! 在平时写代码的时候经常会用到string和int数据类型的转换 由于java和python在string和int数据类型转换的时候是不一样的 下面总结了java和python ...

  6. python中string格式化

    python中可以对string, int, float等数据类型进行格式化操作.下面举例来说明一些常用操作. 先贴出 python 对 String Formatting Operations 讲解 ...

  7. Python中Template使用的一个小技巧

    Python中Template是string中的一个类,可以将字符串的格式固定下来,重复利用. from string import Template s = Template("there ...

  8. python raw String 获取字符串变量中的反斜杠

    常用的获取raw string的方式为: >>>r'\n' \n 不能用在字符串变量中,获取字符串变量中的反斜杠如下: tab = '\n' >>>tab.enco ...

  9. 在python中使用print()时,raw write()返回无效的长度:OSError: raw write() returned invalid length 254 (should have been between 0 and 127)

    写出一个不是code的bug,很烦恼,解决了挺长时间,都翻到外文来看,不过还是解决了,只尝试了一种简单可观的方法,希望对大家有用 我正在使用Django与Keras(tensorflow)来训练一个模 ...

随机推荐

  1. python 本地时间+8小时

    current_time = (datetime.datetime.now() + datetime.timedelta(hours=8)).strftime('%Y-%m-%d %H:%M:%S')

  2. 排行榜 和 zset

    ZSET 使用 https://blog.csdn.net/weixin_37490221/article/details/78135036 https://www.cnblogs.com/chenz ...

  3. fiddle4 弱网测试

    下载:https://www.telerik.com/download/fiddler/fiddler4 参考:https://blog.csdn.net/qq_28905427/article/de ...

  4. TP5接口开发之异常处理接管

    前几天在开发的时候用到了第三方的扩展包,使用过程中第三方扩展包抛出了异常 因为这边是接口开发,需要返回错误代码以及提示信息等,所以就需要接管异常处理. 此文章只做笔记,有不对或不详细的地方欢迎大家留言 ...

  5. C/C++ 指针常量和常量指针

    为了区分是指向常量的指针还是const指针(表示指针本身是常量) 一个简便方法:从由往左读,遇到p就替换为“p is a”,遇到*就替换为“point to”,其余不变. const int * p ...

  6. golang ---Learn Concurrency

    https://github.com/golang/go/wiki/LearnConcurrency 实例1: package main import ( "fmt" " ...

  7. java加密解密工具类

    package com.founder.mrp.util; import java.nio.charset.StandardCharsets; import java.security.Key; im ...

  8. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile

    更换当前jdk版本为项目所需jdk版本即可

  9. Springboot - java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'

    Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning a simple key in 'reader', lin ...

  10. C++ 中的静态成员函数与静态成员变量

    于CSDN 2014-01-17 与静态数据成员一样,静态成员函数是类的一部分,而不是对象的一部分.如果要在类外调用公用的静态成员函数,要用类名和域运算符"∷".如Box∷volu ...