Python automatically adds serial numbers to items.

Source: Internet
Author: User

Function involved: for in int () Enumerate(return value does not accept string type after adding ":")

1i = ["Computer","Water Bottle","Mouse","keyboard"]2  forKey,zifuinchEnumerate (i):#key equals enumerate auto-assigned zero-based number3     Print(Key,zifu)4QQ = input ("Please enter the desired product:")5INP_NM =Int (QQ)6 Print(I[INP_NM])

1 i = ["Computer","Water Bottle","Mouse","keyboard"]2 forKey,zifuinchEnumerate (i,1):#key equals enumerate automatically assigned a number starting from 1, 1 can be arbitrarily modified. 3Print(Key,zifu)4 QQ = input ("Please enter the desired product:")5 inp_nm =Int (QQ)6Print(I[INP_NM])

The above, although the enumerate starting from 1, but in essence, from the beginning of 0 to assign value

1 i = ["Computer","Water Bottle","Mouse","keyboard"]2 forKey,zifuinchEnumerate (i,1):#key equals enumerate automatically assigned a number starting from 1, 1 can be arbitrarily modified. 3Print(Key,zifu)4 QQ = input ("Please enter the desired product:")5 inp_nm =Int (QQ)6Print(I[inp_nm-1])

In line 6th Inp_nm minus 1,ok.

Python automatically adds serial numbers to items.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.