Python Beginner 1

Source: Internet
Author: User

List one of the data types built into the:P Ython is the list: list . A list is an ordered set of elements that can be added and removed at any time.

Constructing the list is very simple,  [ ]  just by enclosing all the elements of the list in the code above, which is a list object. In general, we assign a list to a variable so that it can be referenced by a variable to the list

Because Python is a dynamic language, the elements contained in the list are not required to be of the same data type, and we can completely include a variety of data in the list

Countdown : The second-to-last use-2 means that the countdown to the third use-3 means that the penultimate fourth uses-4 means:

list Additions and deletions : list  append()  method to append the new element to the end of the list

The method is to use the list  insert() method, which accepts two parameters, the first parameter is the index number, the second parameter is the new element to be added

You can delete the last element by using the list pop() method, {pop () Delete to delete, cannot appear like pop (2), pop (3) This}

tuple:tuple is another ordered list, Chinese translates to "tuples". Tuple and list are very similar, however, once a tuple is created, it cannot be modified, the only difference between creating a tuple and creating a list is to ( ) replace the [ ],获取 tuple 元素的方式和 list 是一模一样的,我们可以正常使用 t[0],t[-1]等索引方式访问元素,

      但是不能赋值成别的元素.()both can represent a tuple, and can be used as parentheses to indicate the priority of the operation, the result (1) is calculated by the Python interpreter results 1, resulting in we get not a tuple, but an integer 1. It is precisely because the tuple with the () definition of a single element is ambiguous, so Python specifies that the element tuple should have a comma ",", which avoids ambiguity

Python Beginner 1

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.