Tools, FAQ, Tutorials:
'bytes' Values are Objects
Are "bytes" values objects in Python?
✍: FYIcenter.com
Yes, "bytes" values are objects in Python. In fact, all data values in Python are objects.
In Python, "bytes" is defined as an object class with the following interesting properties, constructors, and methods:
bytes.__doc__ - Property holding a short description of "bytes" objects.
bytes.__new__() - Constructor returning a "bytes" object. It can be invoked as bytes(). For example:
>>> bytes.__new__(bytes,b'FYIcenter.com') b'FYIcenter.com' >>> bytes(b'FYIcenter.com') b'FYIcenter.com'
bytes.__getitem__() - Instance method for the [] operation, returning the byte (as an "int") of the bytes at the given position. For example:
>>> b'FYIcenter.com'.__getitem__(2) 73 >>> b'FYIcenter.com'[2] 73 >>> hex(73) '0x49' >>> "\x49" 'I'
bytes.find() - Instance method searching for the given byte and returning the position in the bytes. For example:
>>> b'FYIcenter.com'.find(b'I') 2 >>> b'FYIcenter.com'.find(73) 2
You can use the dir(bytes) function to see all members of the "bytes" class:
>>> dir(bytes) ['__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', 'center', 'count', 'decode', 'end swith', 'expandtabs', 'find', 'fromhex', 'hex', 'index', 'isalnum', 'isalpha', ' isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpar tition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swap case', 'title', 'translate', 'upper', 'zfill']
2022-12-03, 1300🔥, 0💬
Popular Posts:
What is the Azure AD v1.0 OpenID Metadata Document? Azure AD v1.0 OpenID Metadata Document is an onl...
How to run CMD Commands in Dockerfile to change Windows Docker images? When building a new Windows i...
How to read RSS validation errors at w3.org? If your RSS feed has errors, the RSS validator at w3.or...
How to search for the first match of a regular expression using re.search()? The re.search() functio...
Where to get a real Atom XML example? You can follow this tutorial to get a real Atom XML example: 1...