python中output的使用_python 常用功能之文本处理

前言

在生活、工作中,python

一直都是一个好帮手。在

python

的众多功能中,我觉

得文本处理是最常用的。下面是平常使用中的一些总结。环境是

python 3.3

0. 基础

python

中,使用

str

对象来保存字符串。str

对象的建立很简单,使用单引

号或双引号或

3

个单引号即可。例如:

s=

'nice'

#output: nice

s=

"nice"

#output: nice

s=

"Let's go"

#output: Let's go

s=

'"nice"'

#output: "nice"

s=str(1)

#output: 1

s=

'''nice

day'''

#output: nice

#output: day

python

中,\n

代表换行符,\t

代表

tab

python

中,引用

str

中的某一段的内容很容易。例如:

s=

'123456789'

s[0]

#第一个字符:     output: 1

s[-1]

#倒数第一个字符: output: 9

s[:2]

#前

2

个字符:     output: 12

s[-2:]

#后

2

个字符:     output: 89

s[2:-2]

#去掉前

2

个和后

2

个剩余的字符 output:34567

python

中,判断某一字符串是否在另一个字符串中:

'nice'

in

'nice day'

#output :True

task 1.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值