-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''? –