Python字符串方法详解

python对整型没有限制,不同于C语言会溢出¶

import math
math.e
2.718281828459045
and 与 or 或 not 非 8z,|,~ 按位与或非

bin(0b1011001 & 0b1101101)
‘0b1001001’

1> 2 and 3>5
False

2 ** 2 ** 3
256
序列型数据:字符串str"",元祖tuple(),列表list[],字节数据bytes,bytearray

对于元组,圆括号不是必要的,逗号是必要的

a = 1,2,3
type(a)
tuple

a * 3
(1, 2, 3, 1, 2, 3, 1, 2, 3)

s = [1,2,3,4,5,6,7]
s[1:3]
[2, 3]

s[2:5]
[3, 4, 5]

s[5:1]
[]

s[1:6:2]
[2, 4, 6]

s[2::2]
[3, 5, 7]

s1 = ‘axd’
sorted(s1)
[‘a’, ‘d’, ‘x’]

s2=(1,4,2)
sorted(s2)
[1, 2, 4]

sorted(s2,reverse = True)
[4, 2, 1]

s3 = ‘abAC’
sorted(s3,key=str.lower)
[‘a’, ‘A’, ‘b’, ‘C’]
序列的排序操作,格式:sorted(s,key = None,reverse = False)

sorted(s3)
[‘A’, ‘C’, ‘a’, ‘b’]

all([1,2,3,4,5,6,0,8])
False

any([1,2,3,4,5,6,0,8])
True

a,b=(1,2)

a
1

b
2

a,*b,c = [2,3,5,7,8,67,9,0]

b
[3, 5, 7, 8, 67, 9]

,,*b = [2,3,5,7,8,67,9,0]

b
[5, 7, 8, 67, 9, 0]

,*middles, = sorted([98,86,99,93,88,95,91])
middles

Unicode与单字符转换 ord - char 内置函数:dir

http://www.cnblogs.com/f-ck-need-u

s = ‘PYTHON’
s.center(30,’*’)
PYTHON

s = ‘17080666’
s.zfill(10)
‘0017080666’

s = ‘-17080666’
s.zfill(12)
‘-00017080666’

’ spacious '.lstrip()
'spacious ’

’ spacious ‘.rstrip()
’ spacious’

'spacious '.lstrip(‘s’)
'pacious ’

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值