You can filter
the string by digits using str.isdigit
method,
>>> int(filter(str.isdigit, str1))
3158
More Related Contents:
- Finding and counting the frequency of known pairs of words in multiple files [closed]
- How to handle special cases in my Python code?
- Unable to use convert strings into integers for a for loop
- Convert bytes to a string
- How can I concatenate str and int objects?
- Which is the preferred way to concatenate a string in Python?
- How to use string.replace() in python 3.x
- Pandas Extract Number from String
- How to convert ‘binary string’ to normal string in Python3?
- Why are str.count(”) and len(str) giving different output?
- Python – difference between two strings
- Most pythonic way to interleave two strings
- Removing control characters from a string in python
- Python 3.1.1 string to hex
- Count number of words per row
- How to explain the str.maketrans function in Python 3.6?
- What is a clean way to convert a string percent to a float?
- How can I split a string of a mathematical expressions in python?
- Why do numbers in a string become “x0n” when a backslash precedes them?
- can only concatenate str (not “bytes”) to str
- What’s the difference between str.isdigit(), isnumeric() and isdecimal() in Python?
- Print without b’ prefix for bytes in Python 3
- “TypeError: a bytes-like object is required, not ‘str'” when handling file content in Python 3
- How can I use f-string with a variable, not with a string literal?
- String-based enum in Python
- Deleting consonants from a string in Python
- What is internal representation of string in Python 3.x
- Finding the position of a word in a string
- Why are str.count(”) and len(str) giving different outputs when used on an empty string?
- Convert bytes to a string in python 3