25
'a'.translate({'a':'b'})
'b'
के बजाय 'a'
वापस क्यों करता है? मैं अजगर 3. उपयोग कर रहा हूँपायथन 3 में str.translate क्यों काम नहीं करता है?
'a'.translate({'a':'b'})
'b'
के बजाय 'a'
वापस क्यों करता है? मैं अजगर 3. उपयोग कर रहा हूँपायथन 3 में str.translate क्यों काम नहीं करता है?
इस्तेमाल किया कुंजी पात्रों में से ऑर्डिनल्स, नहीं वर्ण खुद को कर रहे हैं:
'a'.translate({ord('a'): 'b'})
यह होने के लिए str.maketrans
>>> 'a'.translate(str.maketrans('a', 'b'))
'b'
>>> help(str.translate)
Help on method_descriptor:
translate(...)
S.translate(table) -> str
Return a copy of the string S, where all characters have been mapped
through the given translation table, which must be a mapping of
Unicode ordinals to Unicode ordinals, strings, or None.
Unmapped characters are left untouched. Characters mapped to None
are deleted.
केवल कुंजी जरूरतों उपयोग करना आसान हो एक ordinal (http://docs.python.org/3/library/stdtypes.html#str.translate) – Volatility
त्वरित उत्तर के लिए धन्यवाद, मैं जल्द ही स्वीकार करूंगा। – fhucho
:(क्या मुझे याद आया जब जैमिलैक ने निर्माता को पोस्ट किया? – TerryA