python编程入门----位操作与字符串操作

1. 位操作

  • (数字在内存中是补码形式存在;正数的原码,反码,补码完全相同;负数的反码,与原码符号位相同,其他位相反;负数的补码是反码加1)
  • np.bitewise_and(num1, num2) #按位与
  • np.bitewise_or(num1, num2) #按位或
  • np.invert(num) #按位取反(~:表示按位取反操作) ~x = -(x+1)
  • np.left_shift(number, num_shift) #将number的数字二进制左移num_shift位
  • np.right_shift(number, num_shift) #将number的数字二进制右移num_shift位
  • bin(17) #表示数字的二进制形式, 0b10001
  • np.binary_repr(10, width = 8) # 00001010

2. 字符串操作

  • np.char.add(list1, list2) #将俩个列表中对应字符串连接,列表形状不同,不能连接
  • np.char.multiply(str, num) #对str对象重复拼接num次,np.char.multiply(["hello", 'bobo'], 3) :['hellohellohello' 'bobobobobobo']
  • np.char.center(str, width, fillchar) #字符串居中,左右用fillchar填充:fillchar为单字符,否则报错
  • np.char.capitalize(str) #将字符串的第一个字母大写
  • np.char.title(str) #将字符串中的每一个字母大写
  • np.char.lower(str) #函数对数组的每个元素转换为小写。它对每个元素调用 str.lower
  • np.char.upper(str) #功能与上类似,转为大写
  • np.char.splitlines() #'\n'以换行符分割字符串
  • np.char.join() #函数通过指定分隔符来连接数组中的元素或字符串
  • np.char.replace(str, replace_str, prepare_str) #函数使用新字符串prepare_str替换字符串中的所有子字符串replace_str
  • np.char.encode() #对数组中的每个元素调用 str.encode, 默认编码是 utf-8,编码器
  • np.char.decode() #同上,函数对编码的元素进行 str.decode() 解码

转载于:https://my.oschina.net/u/3127014/blog/2966412

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值