If list index exists, do X

前端 未结 12 882
清酒与你
清酒与你 2020-12-02 11:41

In my program, user inputs number n, and then inputs n number of strings, which get stored in a list.

I need to code such that if a certain

12条回答
  •  心在旅途
    2020-12-02 12:30

    A lot of answers, not the simple one.

    To check if a index 'id' exists at dictionary dict:

    dic = {}
    dic['name'] = "joao"
    dic['age']  = "39"
    
    if 'age' in dic
    

    returns true if 'age' exists.

提交回复
热议问题