Why is python so different?

Source: Internet
Author: User

Compared to Java, C #, these programming languages, Python is very flexible and very color. Language design is sometimes illogical, but intuitive and convenient. It's easy to get started with people who don't have a language base.

List slices in a list operation:

>>> t=[0,1,2,3,4,5,6]

>>> T[1:3]
[1, 2]

The colon two-edged number represents the position, and the number starting with the array subscript 0 is its position, and the common sense is different, the habit is good.

The right side of the colon does not represent the length. Just the location.

----------------------------------------------------------------------------------

"List Test"
def test (), int:
t=[0,1, 2, 3, 4, 5, 6]
T.append ([55,56])
Print (t)
T.extend ([7,8])
Print (t)
T.pop (7)
Print (t)
T.sort (reverse= True)
Print (t)
return 0


Test ()
return Result:

[0, 1, 2, 3, 4, 5, 6, [55, 56]]
[0, 1, 2, 3, 4, 5, 6, [55, 56], 7, 8]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
[8, 7, 6, 5, 4, 3, 2, 1, 0]

"Delete Element"
def deleteItem () int:
t = [0, 1, 23, 23, 2, 23, 2]
v = t.pop (0) #删除同时返回值, equivalent to fetching data
Print (t)
Print (v)
Del (t[0]) #删除但不返回值
Print (t)
T.remove (2) #只是删除遇到的第一个
Print (t)
return 0


DeleteItem ()
return Result:

[1, 23, 23, 2, 23, 2]
0
[23, 23, 2, 23, 2]
[23, 23, 23, 2]

Why is python so different?

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.