删除打印的生成密码之间的空格
我写了一个Python脚本来破解被遗忘帐户的密码。 但是,每次我打印一个密码时,“入侵/黑客入侵”与其他任何内容之间都有一个空间。
我怀疑空间字符在密码变量中。无论我做什么,我的IDE都不会让我在密码变量中的引号之间删除该空间。如何删除它?
这是代码:
while True:
import random
num ="12"
ans = num + "-"
ans2 = num + "/"
ans3 = num + "_"
length = 3
password ="".join(random.sample(ans,length))
password2 ="".join(random.sample(ans2,length))
password3 ="".join(random.sample(ans3,length))
print("Hacked",password)
print("hacked",password)
print("Hacked",password2)
print("hacked",password2)
print("Hacked",password3)
I wrote a Python script to crack the password of forgotten accounts.
However, everytime I print a password, there is a space between "Hacked/hacked" and whatever else.
I suspect that the space character is somewhere in the password variables. No matter what I do, my IDE won't let me remove that space between the quotes in the password variable. How can I remove it?
Here's the code:
while True:
import random
num ="12"
ans = num + "-"
ans2 = num + "/"
ans3 = num + "_"
length = 3
password ="".join(random.sample(ans,length))
password2 ="".join(random.sample(ans2,length))
password3 ="".join(random.sample(ans3,length))
print("Hacked",password)
print("hacked",password)
print("Hacked",password2)
print("hacked",password2)
print("Hacked",password3)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
解决这个问题的几种方法:
Several ways to solve this:
默认情况下,
print()
将每个参数传递到一个空间中。您可以通过指定sep
参数(在这种情况下,要将空字符串用作分隔器)来覆盖此问题。例如,您可以执行以下操作:By default,
print()
separates each argument passed to it with a space. You can override this by specifying thesep
parameter (in this case, you want to use the empty string as the separator). For example, you can do the following:此外,您还可以使用F弦来格式化输出:
In addition, you could also use an f-string to format your output:
有一个简单的解决方案
而不是
Got a straightforward solution
Instead of