Python如何从特定字符串中获取参数

时间:2018-03-23 21:12:35

标签: python string input

我正在做的学校项目是复数的计算器。我写了一个函数来计算它,但我不知道如何切割输入字符串以从中生成单个参数。

看起来像这样:

public class MyInnerViewModel {

    public int getAttr() {
        return 1234;
    }
}

它的第一个数字,第二个,操作和另外两个参数。我想把它分割成:在这里输入代码

in1: [complex(1.0, 1.0), complex(1.0, 1.0), ’*’, False, ’nazwa’]

in2: [complex(1 , 1), 2, ’+’, True, ’test’]

和另外2人。 我尝试了input()。split()但是它像这样拆分:[(complex(1.0 | 1.0)|'*'etc。

2 个答案:

答案 0 :(得分:1)

input1 = [complex(1.0, 1.0), complex(1.0, 1.0), '*', False, 'nazwa']
number1 = input1[0]
number2 = input1[1]
noperation = input1[2]

答案 1 :(得分:0)

你可以使用,input1 [index] =输入("你的消息在这里") 您也可以将输入转换为所需的基本类型,例如, input1 [index] = int(输入("你的消息在这里"))