Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python输出列表_Python - Fatal编程技术网

Python输出列表

Python输出列表,python,Python,我正在用python创建一个程序,从用户的输入中生成一个随机密码。到目前为止,我的代码是: from random import * symbols = ['!','"','£','$','%','^','&','*','(',')','-','_','=','/','*','-','+','{','}','[',']',':',';','@','>','#','~','<',',','.','?'] rand1 = randint(0,32) rand2 = randin

我正在用python创建一个程序,从用户的输入中生成一个随机密码。到目前为止,我的代码是:

from random import *

symbols = ['!','"','£','$','%','^','&','*','(',')','-','_','=','/','*','-','+','{','}','[',']',':',';','@','>','#','~','<',',','.','?']
rand1 = randint(0,32)
rand2 = randint(0,32)

fore = raw_input('Enter your forename')
sur = raw_input('Enter your Surname')
birth = raw_input('Enter you birth year')
password = symbols[rand1], fore[0:2], sur[0:3], birth[2:4], symbols[rand2]
print password
是否还有其他方法可以去除括号和逗号等多余字符?

请尝试
print'。加入(密码)

看一下这里的地图。这将把您创建的元组连接到一个字符串中

或者,您可以使用@pzp建议的
+
操作符将组件直接连接到字符串中

请查看,其中显示了两种可能的方式。

尝试打印“”。加入(密码)

password = symbols[rand1], fore[0:2], sur[0:3], birth[2:4], symbols[rand2]
看一下这里的地图。这将把您创建的元组连接到一个字符串中

或者,您可以使用@pzp建议的
+
操作符将组件直接连接到字符串中

看一看,它显示了两种可能的方式

password = symbols[rand1], fore[0:2], sur[0:3], birth[2:4], symbols[rand2]
应该是

password = symbols[rand1] + fore[0:2] + sur[0:3] + birth[2:4] + symbols[rand2]
应该是

password = symbols[rand1] + fore[0:2] + sur[0:3] + birth[2:4] + symbols[rand2]

你好吗?这些答案对你有用吗?@T3H40你给出的解决方案有效!谢谢!:)你好吗?这些答案对你有用吗?@T3H40你给出的解决方案有效!谢谢!:)