This question already has answers here:
replace all characters in a string with asterisks
                                
                                    (4个答案)
                                
                        
                                2年前关闭。
            
                    
str0 = input("Enter str: ")

str0 = str0.replace(str0, '_')

print(str0)


我需要在不使用循环或条件的情况下替换每个字符

最佳答案

str0 = input("Enter str: ")

str0 = '_'*len(str0)

print(str0)


应该管用。乘法会放置正确数量的_,以便将其全部替换。

关于python - 用没有循环的特定单个字符python替换给定字符串的所有字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49085712/

10-10 08:24