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

1. 位操做api

  • (数字在内存中是补码形式存在;正数的原码,反码,补码彻底相同;负数的反码,与原码符号位相同,其余位相反;负数的补码是反码加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() 解码
相关文章
相关标签/搜索