在这篇文章中,我们需要在列表中所有项目的开头输入字符串。
例如:给定字符串=“ Tutorials_Point”,并且List包含多个元素,例如“ 1”,“ 2”等。因此,在此我们需要在“ 1”,“ 2”之前添加Tutorials_Point。
sample_list = [1, 2, 3] print(['Tutorials_Point{0}'.format(i) for i in sample_list])
输出结果
//['Tutorials_Point1', 'Tutorials_Point2', 'Tutorials_Point3']
sample_list = [1, 2, 3] sample_str = 'Tutorials_Point' sample_str += '{0}' sample_list = ((map(sample_str.format, sample_list))) print(sample_list)
输出结果
//['Tutorials_Point1', 'Tutorials_Point2', 'Tutorials_Point3']