小编oba*_*ami的帖子

在 Python 中使用 \n 作为普通字符串

我正在使用数字制作一个字符串计算器。例如: 154 + 246 = 154246

因此,用户将输入一组数字,以使用 分隔数字\n。如您所知,\n用于创建新行,但我需要将 at 用作任何普通字符串。我需要将使用的数字\n分成一个列表。

代码:

num_list = []
# this function will add a number to the list
def ask_num():
    # ask for a number (we will make it a string so we can add comma and /n)
    num = input("Enter numbers: ")

    
# run the function for asking numbers
ask_num()
Run Code Online (Sandbox Code Playgroud)

python

3
推荐指数
2
解决办法
944
查看次数

标签 统计

python ×1