日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python3编码转换_Python3编码转换

發布時間:2025/4/5 python 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python3编码转换_Python3编码转换 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

沒有什么編碼是不能轉的import hashlib

import base64

# string to md5

input_text = "我能吞下玻璃而不傷身體"

md5_string = hashlib.md5(input_text.encode(encoding='utf8')).hexdigest()

# 2e536f0d3a95e676e30afb2b511c6fe2

# string to base64

base64_string = base64.b64encode(input_text.encode('utf-8')).decode('utf-8')

# 5oiR6IO95ZCe5LiL546755KD6ICM5LiN5Lyk6Lqr5L2T

# base64 to string

output_text = base64.b64decode(base64_string).decode(encoding='utf8')

# 我能吞下玻璃而不傷身體

# URL Decode quote/unquote

import urllib.parse

result = urllib.parse.unquote("%E6%88%91%E8%83%BD%E5%90%9E%E4%B8%8B%E7%8E%BB%E7%92%83%E8%80%8C%E4%B8%8D%E4%BC%A4%E8%BA%AB%E4%BD%93")

# 我能吞下玻璃而不傷身體

result = urllib.parse.quote(input_text)

#%E6%88%91%E8%83%BD%E5%90%9E%E4%B8%8B%E7%8E%BB%E7%92%83%E8%80%8C%E4%B8%8D%E4%BC%A4%E8%BA%AB%E4%BD%93

# string to hex

bytes_string = input_text.encode()

bytes_string = b'\xe6\x88\x91\xe8\x83\xbd\xe5\x90\x9e\xe4\xb8\x8b\xe7\x8e\xbb\xe7\x92\x83\xe8\x80\x8c\xe4\xb8\x8d\xe4\xbc\xa4\xe8\xba\xab\xe4\xbd\x93'

hex_str = bytes_string.hex()

# e68891e883bde5909ee4b88be78ebbe79283e8808ce4b88de4bca4e8baabe4bd93

# hex to string

text = bytes.fromhex(hex_str).decode()

# 我能吞下玻璃而不傷身體

ipv4字符串與數字轉換import socket

import struct

ip = '127.0.0.1'

int_ip = struct.unpack('!I', socket.inet_aton(ip))[0]

print(int_ip)

str_ip = socket.inet_ntoa(struct.pack('!I', int_ip))

print(str_ip)

總結

以上是生活随笔為你收集整理的python3编码转换_Python3编码转换的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。