Python 基础之字符串string详解及实例
发布时间:2020-05-24 11:10:20 所属栏目:Python 来源:互联网
导读:Python字符串(string)详解及代码Python的字符串可以使用单引号('),双引号("),三引号(''');三引号(''')里面,可以添加单引号和双引号,也可以通过转义序列()添加;
|
Python字符串(string) 详解 及 代码 Python的字符串可以使用单引号('),双引号("),三引号('''); 三引号(''')里面,可以添加单引号和双引号,也可以通过转义序列()添加; 字符串前面添加限定词R或r,表示是自然字符串(nature string),可以忽略里面的格式限制; 在物理行末尾添加"",可以连接下一个物理行; 括号,方括号,大括号也可以一定限度的扩充物理行; 具体参见代码注释; 代码如下:
# -*- coding: utf-8 -*-
#====================
#File: abop.py
#Author: Wendy
#Date: 2013-12-03
#====================
#eclipse pydev,python3.3
#三引号可以自由的使用双引号("")和单引号('')
s = ''''' I am a girl and like heels.
Hello,"python" sister. '''
#转义序列""
st = '''''Hello,girls,l like ('''). '''
#字符串放在一起自动连接
sa = 'Girls are ''the best. '
#r表示自然字符串,不会进行转义(n)
sr = r"nature is good. n {0}"
#""表示连接字符串
sc = 'Oh,the lines are too
large'
#括号,大括号,可以限定范围,不用使用转义
print("the braces can do {thing}.".
format(thing="lady"))
print(s)
print(st)
print(sa)
print(sr)
print(sc)
输出:
the braces can do lady.
I am a girl and like heels.
Hello,"python" sister.
Hello,l like (''').
Girls are the best.
nature is good. n {0}
Oh,the lines are too large
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持! (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 【Python有坑系列】python中编码问题——unicode, gbk, utf
- Python 生成POST/GET包构建及随机字符串的简单示例
- python 与redis
- python – Pandas:有没有办法使用类似’droplevel’的东西
- python压缩和读取.tar.bz2格式的压缩包
- 批量修改图片大小Python代码
- python ntlk donwload给解析器eror
- 简单掌握Python的Collections模块中counter结构的用法
- 的IntEnum返回AttributeError:无法设置属性
- Django 1.10中有哪些django.core.context_processors.reque
