Python-字符串
来源:互联网 发布:网络主播陷整形贷 编辑:程序博客网 时间:2024/05/21 06:26
引号
单引号与双引号的作用是一样的,使用由个人的习惯决定(如果字符串中含有单引号,则用双引号表示字符串,反之则用单引号表示字符串)。三引号是Python特有的,用了三引号可以输入单引号,双引号以及换行等字符,也就是可以多行输入。
>>>>"hello world"'hello world'>>>'hello world''hello world'>>>'''hello...world''''hello\nworld'
字符串表示
str函数会把值转换成合理形式的字符串,也就是符合用户阅读习惯的形式。repr则以合法的python表达式的形式来表示,也就是适应于程序理解的形式。
>>>>repr('hello world')" 'hello world' ">>>str('hello world')'hello world'
原始字符串与转义
与以前学过的转义符号一样,可以通过使用转义符号'\'在字符串里面包含引号,换行等字符的表示。但是如果想'\n'这样的字符串只是希望表示单个的字符的意义,但是通常情况下会被认为是转义,所以就需要用到原始字符串这一形式,它不会再把反斜线后面的字符转义,但是不能在原始字符串结尾输入反斜线。
>>>print 'hello\nworld'helloworld>>>print 'hello\nworld'hello\nworld
0 0
- Python字符串
- Python 字符串
- python字符串
- python 字符串
- 【python】-字符串
- python 字符串
- python字符串
- python 字符串
- python,字符串
- python 字符串
- Python字符串
- Python字符串
- python字符串
- Python 字符串
- python 字符串
- Python 字符串
- Python字符串
- python 字符串
- 六星经典CSAPP笔记(1)计算机系统巡游
- php学习笔记(二十九)目录安全
- SDUT OJ 3045 迷之图论 (树的直径)
- ios中的动画小结(view层次和layer层次)
- 构建C协程之概述
- Python-字符串
- HDU1398 Square Coins(母函数)
- 最小生成树判断唯一性_POJ1679
- JDK 里的 PriorityQueue
- PhotoShop算法实现进阶-锐化滤镜-钝化蒙版(二十八)
- Linux之Makefile(error)
- 使用WCF(Windows Communication Fundation)示例
- 郑州大学第八届ACM程序设计大赛D题 唐学长的蜜月之旅 续集
- Codeforces Round #277.5 (Div. 2)F题