The 13th lesson of Python Learning-other data types, others

Source: Internet
Author: User

Enumerate (iterable,start=0)

(the subscript start position of the custom list) list variables, to define the number of open: default is 0 start

#!/usr/bin/env python#-*-coding:utf-8-*-a=["Juvenile","Youth","Adult","old age"] forKvinchEnumerate (a,1):    Print(k,v)#Print 1 Teenager 2 Youth 3 adult 4 old

Enumerate () Combine the application, enter the life stage serial number, print out the corresponding stage

#!/usr/bin/env python#-*-coding:utf-8-*-a=["Juvenile","Youth","Adult","old age"] forKvinchEnumerate (a,1):    Print(k,v) b=input ("Please enter the life stage number:") C=Int (b) d=A[c]Print(d)#input 1 Print youth

Range () automatically creates a list (py2.7 version)

(Automatically create list, less than how many start to create, greater than how many start to stop, create list interval number default can not write)

# !/usr/bin/env python # -*-coding:utf-8-*-a=range (1,11)print(a)#[1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]

Xrange () Auto-Create list (py2.7 version)

Unlike range, xrange requires a for loop before it is created

# !/usr/bin/env python # -*-coding:utf-8-*-a=xrange (1,11) for in A:    print(b )# Print 1 2 3 4 5 6 7 8 9

Range can also create a list from large to small

format : Ragne (max, Min, step)

Note: The decimal number itself cannot be taken, from large numbers to decimals whose step size is negative

such as: printing 10 9 8 7 6 5 4 3 2 1

Range (10,0,-1)

# !/usr/bin/env python # -*-coding:utf-8-*-a=range (10,0,-1) for in A:    Print  (b) # Print 9 8 7 6 5 4 3 2 1

The 13th lesson of Python Learning-other data types, others

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.