Creation, input and output of two-dimensional arrays in Python

Source: Internet
Author: User
Tags shallow copy

"For loop: For I in Range (X,y,dir):    Pass First this interval is left closed right open second dir in the case of omitting the default is 1, that is, each time plus one, you can also specify the python array: Python is not an array,  But you can use list instead of array one-dimensional arrays: Method One: Arr=[0 for x in range (0,n)] Method Two: Arr=[0]*10 method One and method two are equivalent two-dimensional arrays: Method One: Arr=[[0 for x in range (0,n)] for y in Range (0,m)] method two: Arr=[[0]*3]*3 but the two are different in the second method, if arr[0][1]=3, then arr=[[0,3,0],[0,3,0],[0,3,0]] Reason: the Python standard The library is the list * N->n shallow copies of list concatenated, n a shallow copy of the list of connections, as long as one of the changes, the other will also follow the change "#计蒜客: Matrix Flip #!/usr/bin/  python#-*-coding:utf-8-*-import mathn,m,ty=[int (x) for x in input (). Strip (). Split ()]arr=[[0 for x in range (0,n)] for y In range (0,m)]for I in Range (0,n):    arr[i]=input (). Split (") if ty==0: for    i in range (0,n): for        J in range (m-1 , -1,-1):            print (arr[i][j],end= "")        print () Else: for    i in range (n-1,-1,-1): for        J in Range (0,m):            Print (arr[i][j],end= "")        print ()

  

Creation, input and output of two-dimensional arrays in Python

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.