How can it happens?
If a match found in the string then the match() function will return an object representing the match. The match is a string, am i right ? How a string can be an object?
7/18/2021 4:27:03 AM
Amit Ranjan Sahoo
8 Answers
New AnswerAmit Ranjan Sahoo In low-level languages like 'C', there is no data-type known as a 'string'; they're just represented as an array of characters, which is what it actually is. In Python, 'str' is a class (a variable that stores the reference to the string-class, accurately speaking). This class includes all the string properties and methods like __class__, isalpha(), etcetera along with the character array which makes up the string (a lot more are there). Whenever a string is created, an instance of this class is made in the heap and the reference to it returned. Everything is an object in Python. P.S. I guess that the real question was to know what the match function returns. It returns a match object, btw.
Amit Ranjan Sahoo The "match object" is NOT a string. Rather it's an instance of the Match class: https://docs.python.org/3/library/re.html#match-objects You can see this better in a simple example: https://code.sololearn.com/coW3Ue21BrNk/?ref=app
Amit Ranjan Sahoo All objects other than "", 0, [], {}, None, 0.0 and False have a boolean value of 1 (True). So, if 'adf': print("This will be printed") else: print("This won't be printed") # Hope this helps
Calvin Thomas Please tell me that if re.match() returns an object then how "If statement" is working?