python - 自定义字符串函数
问题描述
我想做一个类似于python中字符串的内置函数的函数。
例如: foo.upper()
我不想制作一个对象来执行此操作,只需使用类中的简单函数更改字符串即可。
这是代码将类似于
class autokey():
def encrypt(self, string, key):
# * Code to encrypt message *
return encrypted_message
string = "test"
print(string.autokey.encrypt())
解决方案
推荐阅读
- php - 尝试在 localhost php 中发送电子邮件时出错
- python - CVXPY 是否支持 trace(XT@A@X),其中 X、A 都是矩阵?
- javascript - 如何解决javascript中的异步等待问题?
- javascript - 从 promise 导出变量然后阻塞
- node.js - 谷歌语音到文本无法在 nodejs 上运行
- java - 获取方法中的所有变量名
- python - python从朋友那里接收数据
- c - 在 linux 内核模块中克隆一个文件
- python - 如何使用美丽的汤刮标签属性列表?
- python - 比较两个字符串并在Python中提取变量数据的值