首页 > 解决方案 > 自定义字符串函数

问题描述

我想做一个类似于python中字符串的内置函数的函数。

例如: foo.upper()

我不想制作一个对象来执行此操作,只需使用类中的简单函数更改字符串即可。

这是代码将类似于

class autokey():
   def encrypt(self, string, key):
   # * Code to encrypt message *
   return encrypted_message

string = "test"
print(string.autokey.encrypt())

标签: pythonstringfunctionclass

解决方案


推荐阅读