How to implement conversion function by python3 str or bytes
This article mainly explains "how to realize the conversion function in python3 str or bytes". The explanation in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "how to realize the conversion function in python3 str or bytes" together!
str or bytes always returns str#!/ usr/bin/env python# -*- coding: utf-8 -*-def to_str(bytes_or_str): if isinstance(bytes_or_str, bytes): value = bytes_or_str.decode('utf-8') else: value = bytes_or_str return value #Instance of strstr or bytes always returns bytes#!/ usr/bin/env python# -*- coding: utf-8 -*-def to_str(bytes_or_str): if isinstance(bytes_or_str, str): value = bytes_or_str.encode('utf-8') else: value = bytes_or_str return value #Instance of bytes Thank you for reading, the above is "python3 str or bytes how to implement the conversion function" content, after the study of this article, I believe that everyone on python3 str or bytes how to implement the conversion function This problem has a deeper understanding, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!