简体   繁体   English

如何打印出与列表长度相等的'&'字符串

[英]How to print out a string of a '&', equal to the length of a list

I want to print out a list of the character '&' as many times as there are in a given number. 我想打印一个字符“&”的列表,次数与给定数字相同。 So if the number is 10, I want the result to be '&&&&&&&&&&&' 因此,如果数字为10,我希望结果为'&&&&&&&&&&'

What I have done is turned the int into a list so I can better visualize what I want to perform. 我所做的就是将int转换为一个列表,这样我可以更好地可视化我想要执行的操作。

def print_list_&(size):
    """super serious docstring"""
    result_1 = 1
    result_2 = size + 1
    result = list(range(result_1, result_2))
    return result

I'm stuck on where I go from here. 我被困在从这里去的地方。 This is university work so I'm better off with a push in the right direction than a straight answer. 这是大学的工作,所以与正确的答案相比,向正确的方向发展最好。

'&' * 10 will give you '&&&&&&&&&&' . '&' * 10将给您'&&&&&&&&&&' Therefore it seems you just need '&' * size . 因此,似乎您只需要'&' * size

Python 2: Python 2:

N = int(raw_input())
print '&' * N

Python 3: Python 3:

N = int(input())
print ('&' * N)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打印列表中最长字符串的长度 - print the length of the longest string in the list 断言列表中字符串元素的长度相等 - Asserting equal length of string elements in a list 如何通过检查长度作为字典列表中的元素数来打印字符串 - How to print a string by checking the length as number of elements in list of dictionary python - 如何从列表中的多个字符串中打印1个字符串 - python - how to print 1 string out of multiple string in a list 如何使数据帧列表的长度相等 - How to make a list of dataframes all equal in length 如何从 python 中的列表中获取特定的多个值,如果用户输入等于多个值,则打印 output - How to get the specific multiple value out from a list in python and If the user input is equal to the mulitple values print output 如何打印带有对齐文本的列表列表,rjust() 的整数长度来自列表中字符串的最大长度。 - How to print list of lists with justified text, the integer length to rjust() comes from the largest length of string in the lists. 打印字符串列表的原始字符串值的长度 - Print length of raw string value of an list of strings Python 如何从列表中查找特定字符串并打印出该行? - Python How to find a specific string from a list and print that line out? 如何在一行中打印出字符串和列表-python - how to print out a string and list in one line-python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM