我的代码是
import base64
var = "this is a program for string capitalize method"
var1 = base64.b64encode(bytes('var','utf-8'))
print("String Encode:",end=''),print(var1.encode('base64','strict'))
但是我收到以下错误:
AttributeError:'bytes'对象没有属性'encode'
答案 0 :(得分:0)
第3行替换' var'与var。
第4行直接打印var1。
import base64
var = "this is a program for string capitalize method"
var1 = base64.b64encode(bytes(var,'utf-8')) # to encode above text
print("String Encode:",end=''),print(var1)) # var1 encoded string in bytes