Python 隔离单行中读取的命令和值的步骤
我用python创建了一个列表:Python 隔离单行中读取的命令和值的步骤,python,Python,我用python创建了一个列表: a=[1,2,3,4,5] 我要求用户在一行中输入来自的命令。 e、 g.附加6 除了分离函数“append”和值“6”之外,还有其他方法来执行此操作吗?Jumm append的另一种方法可能是这样,但不喜欢: a= [1,2] b = int(raw_input('give me the number')) a= a+[b] print a 或者使用insert()函数听起来像是在寻找: 现在我们有了action=['append','6'] a = [1
a=[1,2,3,4,5]
我要求用户在一行中输入来自的命令。
e、 g.附加6
除了分离函数“append”和值“6”之外,还有其他方法来执行此操作吗?Jumm append的另一种方法可能是这样,但不喜欢:
a= [1,2]
b = int(raw_input('give me the number'))
a= a+[b]
print a
或者使用insert()函数听起来像是在寻找: 现在我们有了
action=['append','6']
a = [1, 2, 3, 4, 5]
function, value = input('command: ').split()
if function == 'append': a.append(int(value))
a = [1, 2, 3, 4, 5]
user_input = raw_input('next action:') # e.g. append 6
action = append_input.split()