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() 解碼
相關文章
相關標籤/搜索