00问答网
所有问题
python中str.maketrans(x,y)函数前的字符串是干什么的?
初学者,麻烦讲通俗点,谢谢!
举报该问题
其他回答
第1个回答 2022-06-06
初学时,只有变量和函数概念。而python是面向对象语言,对象由属性和方法构成。属性类似变量,方法类似函数,只是他们只属于这个对象,调用时就要用对象.属性和对象.方法()。这里的maketrans就是字符串对象的方法,str是字符串对象。就像养只狗狗叫旺财,让它吃饭,就应该写作:旺财.吃饭(),学到后面就懂了。
本回答被网友采纳
第2个回答 2022-06-06
maketrans不是函数,是str类的方法,在学python的面向对象的时候会学到。前面的字符串就是要操作的对象(可以理解成一个字符串变量)。
比如你写:
string = "Hello"
tr = string.maketrans("eo", "12")
print(string.translate(tr))
这样maketrans()和translate()两个方法就会直接对前面的字符串string进行操作。 (*^▽^*)
输出结果:
H1ll2
相似回答
Python
为啥我这个
maketrans
报错?!
答:
1 maketrans()方法是用于创建字符映射的转换表,所以其两个作为参数
的字符串
长度必须一致.你的两个字符串长度不一致 2 因为你要转换的是字符串类型的数据,而不是byte类型的数据,所以你应该用
str.maketrans()
改正后
的Python
程序如下 a='asdkjsk.fil3asdlkfhksdfgjdksfg'b=str.maketrans('askjdhasf',...
python中maketrans
要引入
什么
包
答:
① s.translate(table
,str)
对字符串s移除str包含的字符,剩下
的字符串
按照table里的字符映射关系替换。table可以理解为转换表,比较'a' -> 'A', 'b'->'B'.② tabel = string.
maketrans(
's1', 's2') s1 和 s2 的长度必须一致,maketrans生成一个转换表,若在s中有s1,则替换为s2,这个...
python
3.3版本,导入
maketrans函数
出错,提示如图
答:
Python
3.3中,已经没有string.maketrans()了,取而代之的是内建
函数,
见参考资料。 追问 哪个内建函数可以代替maketrans()? 追答 新的有三个:bytearray.maketrans()、bytes.maketrans()、
str.maketrans()
参考资料: http://docs.
python
.org/3.3/search.html?q=maketrans&check_keywords=yes&area=default 本回...
python
编写一个程序读入一个文件,将每行内容拆借为单词,剥去单词周围...
答:
word1 =
str.maketrans(
t1,' '*32,'') word2 = word.translate(word1).strip(t2).lower() #去除
字符串
首尾空格并把字母转换成小写 word3 = word2.replace(' ','') print(word3) if __name__ == '__main__': conversion() 可以在我这边文章网页链接讨论下 我刚学 已赞过 已踩过< 你对...
大家正在搜
maketrans python
python translate
python choice函数
python with open
python reverse
python中encode用法
python import
python sample
python random
相关问题
python手册中 x[, y[, z]] 是什么意思 (譬...
享学课堂盘点python字符串是什么及简单操作方法
python中str是什么意思?
Python2.x和3.x下maketrans与transl...
python中str函数是什么意思
python函数是干嘛用的 像什么字符串都是什么干嘛用的?要...
python中“str”是什么意思?
python中str是什么意思