Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to implement conversion function by python3 str or bytes

Shulou Source: shulou.com Published: 2022-06-01 16:30:50 10月01日 Update

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!

Tags: Functions learning content utf-8 that is ideas situations articles more knowledge knowledge points articles follow questions practice push research verification Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology macOS OPPO Reno MariaDB Docker