-3
A
回答
1
正則表達式?
>>> from re import sub
>>> A = 'ABC:123'
>>> sub(r'\D', '', A)
123
+0
**注意:**對問題本身的所有評論都非常正確。這是一個'字符串',而不是'NoneType' – Michael
4
拆分在冒號:
>>> A='ABC:123'
>>> numA = int(A.split(':')[1])
123
1
如何:
>>> import re
>>> def digitsof(a):
... return [int(x) for x in re.findall('\d+', a) ]
...
>>> digitsof('ABC:123')
[123]
>>> digitsof('ABC:123,123')
[123, 123]
>>>
0
一個簡單的過濾功能
A='ABC:123'
filter(lambda s: s.isdigit(), A)
+1
你正在得到ABC,將它改爲isdigit() –
+0
你沒錯,編輯我的答案:) – user2814648
相關問題
- 1. 的Python:訪問NoneType對象
- 2. AttributeError的: 'NoneType' 對象具有在python
- 3. SQLAlchemy的:「NoneType」對象對bulk_update_mappings
- 4. python TypeError:'NoneType'對象沒有屬性'__getitem__'
- 5. python - 'NoneType'對象沒有任何屬性
- 6. Python:'NoneType'對象沒有屬性'decompressobj'
- 7. Python:不能連接str和NoneType對象
- 8. 「NoneType」對象在Python列表理解
- 9. python AttributeError:'NoneType'對象沒有屬性'vtkPVPythonModule'paraview
- 10. Python NoneType對象沒有屬性'get'
- 11. Python TypeError:'NoneType'對象沒有屬性'__getitem__'
- 12. TypeError:'NoneType'對象不可調用 - Python Tkinter
- 13. Python TypeError:'NoneType'對象不可調用
- 14. Python-AttributeError:'NoneType'對象沒有屬性'lower'
- 15. TypeError:'NoneType'對象不可調用(Python)
- 16. Python。 AttributeError:'NoneType'對象沒有屬性'startswith'
- 17. Python - AttributeError:'NoneType'對象沒有屬性'findAll'
- 18. NoneType'對象在python中沒有屬性?
- 19. 「NoneType」對象未標化的
- 20. AttributeError的:「NoneType」對象在allauth
- 21. TypeError:'NoneType'對象不可調用(Python:從HTML數據中刮除)
- 22. 什麼是'NoneType'對象?
- 23. 給'NoneType'對象屬性
- 24. 'NoneType'對象不可訂閱
- 25. Nonetype對象沒有attributte get_datos()
- 26. 'NoneType'對象不可迭代
- 27. AttributeError的:「NoneType」對象有沒有屬性「得到」 - Python的 - OpenERP的
- 28. Python的AttributeError的:「NoneType」對象有沒有屬性「的fileno」
- 29. Python的AttributeError的:「NoneType」對象有沒有屬性「get_text」
- 30. Python的NoneType對象是不可調用的(初級)
這不是一個NoneType,這是一個字符串。你到目前爲止嘗試了什麼? – RemcoGerlich
不,你做**不**有'NoneType'對象;你有一個字符串。 –
如果有非連續的數字會發生什麼? ''ABC:123:456''? –