Python And Perl

Extract Digits from a String in Python

See how to extract digits from a string in Python using a regular expression. import reinputString = ‘QuinStreet2019Year’result = re.sub(“D”, “”, inputString)

Reverse a String in Python

Python’s str string objects have no built-in .reverse() method like you might expect if you’re coming to Python from a different language. str = “devx”print(“reverse string is “, str[::-1])

Get the Size of an Object in Python

Use getsizeof method to retrieve the size of an object in bytes. See below for an example: str = “devx” print(sys.getsizeof(str))

How to Check if a List is Empty in Python

Use one of the following methods to check if a list is empty in Python: a. If not listname: print(“list is empty”)b. if len(listname) == 0: print(“list is empty’)