Tools, FAQ, Tutorials:
'str' Values are Objects
Are "str" values objects in Python?
✍: FYIcenter.com
Yes, "str" values are objects in Python. In fact, all data values in Python are objects.
In Python, "str" is defined as an object class with the following interesting properties, constructors, and methods:
str.__doc__ - Property holding a short description of "str" objects.
str.__new__() - Constructor returning a "str" object. It can be invoked as str(). For example:
>>> str("FYIcenter.com") 'FYIcenter.com' >>> str.__new__(str,"FYIcenter.com") 'FYIcenter.com'
str.__getitem__() - Instance method for the [] operation, returning the character (as a "str") of the string at the given position. For example:
>>> "FYIcenter.com".__getitem__(2) 'I' >>> "FYIcenter.com"[2] 'I' >>> ("FYIcenter.com")[2] 'I'
str.lower() - Instance method converting the string to lower case. For example:
>>> "FYIcenter.com".lower() 'fyicenter.com'
You can use the dir(str) function to see all members of the "str" class:
>>> dir(str) ['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '_ _eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs __', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__' , '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__' , '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'e ncode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isal num', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstr ip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartitio n', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase' , 'title', 'translate', 'upper', 'zfill']
2022-12-03, 1171🔥, 0💬
Popular Posts:
How to use the JSON to XML Conversion Tool at freeformatter.com? If you want to try the JSON to XML ...
How to install "The Windows SDK version 8.1"? I need to build my Visual Studio C++ applications. If ...
How to use the "send-one-way-request" Policy statement to call an extra web service for an Azure API...
Where can I download the EPUB 2.0 sample book "The Metamorphosis" by Franz Kafka? You can following ...
How to Instantiate Chaincode on BYFN Channel? You can follow this tutorial to Instantiate Chaincode ...