numpy.strings.lstrip#
- strings.lstrip(a, chars=None)[source]#
針對 a 中的每個元素,傳回一份已移除前導字元的副本。
- 參數:
- aarray-like,具有
StringDType
、bytes_
或str_
dtype - charsscalar,與 a 具有相同的 dtype,選用
chars 參數是一個字串,指定要移除的字元集。如果為
None
,則 chars 參數預設為移除空白字元。chars 參數不是前綴或後綴;而是會移除其值的所有組合。
- aarray-like,具有
- 傳回值:
- outndarray
StringDType、bytes_ 或 str_ dtype 的輸出陣列,取決於輸入型別
另請參閱
範例
>>> import numpy as np >>> c = np.array(['aAaAaA', ' aA ', 'abBABba']) >>> c array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7') # The 'a' variable is unstripped from c[1] because of leading whitespace. >>> np.strings.lstrip(c, 'a') array(['AaAaA', ' aA ', 'bBABba'], dtype='<U7') >>> np.strings.lstrip(c, 'A') # leaves c unchanged array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7') >>> (np.strings.lstrip(c, ' ') == np.strings.lstrip(c, '')).all() np.False_ >>> (np.strings.lstrip(c, ' ') == np.strings.lstrip(c)).all() np.True_