js代码转python

js代码如下

var e = a.charCodeAt(t).toString(16);这一行不明白

function encode_unicode_param(a) {

    for (var s = "", t = 0; t < a.length; t++) {

        var e = a.charCodeAt(t).toString(16);

        s += 2 == e.length ? "n" + e: e

    }

    return s

}


婷婷同学_
浏览 503回答 1
1回答

jeck猫

python3 下:def encode_unicode_param(s):&nbsp; &nbsp; results = []&nbsp; &nbsp; for char in s:&nbsp; &nbsp; &nbsp; &nbsp; h = hex(ord(char))[2:]&nbsp; &nbsp; &nbsp; &nbsp; format_string = 'n{}' if len(h) == 2 else '{}'&nbsp; &nbsp; &nbsp; &nbsp; results.append(format_string.format(h))&nbsp; &nbsp; return ''.join(results)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript