Love Python, love to learn

Source: Internet
Author: User
Tags ming

List
The list can fit anything.
LST = ["Mobile HDD", "mobile phone", "curse", "Chinese on the Tongue", "Under the Dome", "King Kong"]
Print (lst[3]) #含义: Output List of the third tongue on the Chinese
Print (lst[3][2]) #含义: The second of the third in the output list
LST = ["small fish and flowers not intact", "clan and flowers Full Floor", "Seven kinds of weapons peacock Ling", "Wulin Wai Shi", "Small Li Fei Dao"]
Print (lst[3][2]) #外, the second of the third in the output list
Print (Lst[-2]) #输出列表中倒数第二个
Print (Lst[1:4]) #输出列表中的 [' Clan and Flowers ', ' peacock feather of Seven weapons ', ' Wulin wai Shi ']
Print (Lst[-3:-1]) #输出列表中的倒数第三个, second from the bottom, Gu Tou regardless of the tail
Print (Lst[1::2]) #从第一个开始切 cut to the tail, the step is 2, every two take 1 [' Clan and flowers Full House ', ' Wulin wai Shi ']
Print (Lst[-1:-5:-2]) #含义: Step 2, with a minus sign to cut from right to left, from the penultimate first cut to the bottom fifth, every two to take a [' small Li Fei knife ', ' seven weapons of Peacock Plume ']

List of additions and deletions to change
LST = ["Flower Full Floor", "clan", "Simon blowing Snow", "Sagong pick Star", "Chu Liu Xiang", "Fan Iron Flower"]
Append add after the last element of the list
Lst.append ("The Universe Fan") # operation on the basis of the original
Print (LST) #打印结果为: [' Flower full Floor ', ' Clan ', ' Simon blowing Snow ', ' Sagong pick star ', ' Chu Stay fragrant ', ' fan iron flower ', ' Universe fan ']
Insert XXXX content at XXX location
Lst.insert (1, "flower-filled") #含义: Inserted at index 1, "full of flowers"
Print (LST) #打印结果: [' Flower full floor ', ' flower filled ', ' clan ', ' Simon blowing Snow ', ' Sagong pick star ', ' Chu Hsiang ', ' fan iron Flower ']
Lst.extend (["Zhang Yide", "Liu Xuande", "Cloud Long", "Zhao Zilong", "Zhuge Ming"]) # Iteration Add
Print (LST) #[' Flower House ', ' Clan ', ' Simon blowing Snow ', ' Sagong pick star ', ' Chu Stay incense ', ' fan iron flower ', ' Zhang Yide ', ' Liu Xuande ', ' Cloud Long ', ' Zhao Zilong ', ' Zhuge Ming ']


data = Lst.pop (2) # returns the deleted
Print (data)
Print (LST) #打印输出的结果为: [' Flower full Floor ', ' clan ', ' Sagong ', ' Chu Hsiang ', ' fan iron Flower ']
LST = [' Flower full Floor ', ' Clan ', ' Simon blowing Snow ', ' Sagong pick star ', ' Chu Stay incense ', ' fan iron flower ', ' Zhang Yide ', ' Liu Xuande ', ' Cloud Long ', ' Zhao Zilong ', ' Zhuge Ming ']
Lst.remove ("clan")
Print (LST) # delete element. Print results [' flower full Floor ', ' Simon blowing Snow ', ' Sagong pick star ', ' Chu leave incense ', ' fan iron flower ', ' Zhang Yide ', ' Liu Xuande ', ' Cloud Long ', ' Zhao Zilong ', ' Zhuge Ming ']
Lst.remove ("Li Huan") # if not there will be an error

del Lst[1:3] # slice Delete
Print (LST) #第一项和第二项被删除, printing results for [' Flower full Floor ', ' Sagong pick star ', ' Chu Stay fragrant ', ' fan iron flower ', ' Zhang Yide ', ' Liu Xuande ', ' Cloud Long ', ' Zhao Zilong ', ' Zhuge Ming ']

Lst.clear () #默认是将原来的列表, empty
Print (LST) #打印结果为 []

LST = ["Hundred Step Flying Sword", "Night to Day", "Hundred Schools", "Great Wall", "King of the World"]
LST[0] = "Nine Songs of the day Line" #替换, with "Nine songs" to replace "hundred Step Flying Sword"
Print (LST) #打印结果, [' Nine Songs ', ' Night Day ', ' Hundred Schools ', ' Great Wall ', ' King of the World ']
LST[3] = "Sea Cross" #将原来列表里的第三个, replace with "sea cross"
Print (LST)
Lst[1:3] = ["Bucket broken Sky"] #含义: First delete and add, delete the original list of 1-3, and then add a new string
Lst[1::2] = ["Bucket continent", "Bucket Broken Sky"] #含义: Slice from 1 to cut, always cut to tail, every two to take one, and then add the content to correspond with the space
When the slice is modified. If the step is not 1. Note the number of elements
Print (LST) #打印结果: [' Hundred Step Flying Sword ', ' bucket continent ', ' Hundred Schools ', ' Break the sky ', ' King of the World ']

LST = [' Flower full Floor ', ' Clan ', ' Simon blowing Snow ', ' Sagong pick star ', ' Chu Stay incense ', ' fan iron flower ', ' Zhang Yide ', ' Liu Xuande ', ' Cloud Long ', ' Zhao Zilong ', ' Zhuge Ming ']
For El in lst: # element (elements)
Print (EL) #将列表中的内容, iterative output (output in sequence)

LST = ["Flower Full Floor", "Luxiaofeng", "Ximencuixue", ["Sagong Pick Star", "Chu Xiang", [1, "Fire Cloud", "Cloud Long", "haha"], "grinning"]
Print (lst[3][2][1]) #采用降维, a layer of look good. Meaning to print the first of the second item of the third list

LST = ["Alex", "gay", "Wusir", ["Fan Bingbing", "Li Bingbing", [1, "hotpot", "Ritian", "Chicken Claw"], "reques"]
# 0 1 2 3
# 0 1 2 3
# 0 1 2 3
LST[3][2][2] = Lst[3][2][2].upper () #这行代码的含义是将lst =["Alex", "gay", "Wusir", [①[②]]
["Fan Bingbing", "Li Bingbing", [1, "hotpot", "Ritian", "Chicken Claw"], "reques"] =①
②= [1, "hotpot", "Ritian", "Chicken Claw"]
Print (LST) #打印结果为 [' Alex ', ' gay ', ' wusir ', [' Fan Bingbing ', ' Li Bingbing ', [1, ' hotpot ', ' Ritian ', ' chicken claw '] , ' Reques ']

Lst[3][2][0] = lst[3][2][0] + 99
Print (LST) #打印结果为 [' Alex ', ' gay ', ' wusir ', [' Fan Bingbing ', ' Li Bingbing ', [100, ' hotpot ', ' Ritian ', ' chicken claw ' '], ' reques ']

Print (Lst[3][2][3])
List related actions
LST = [1,5,3,4,3,2,44,3,2,22]
Lst.sort () # Sort. Default Ascending,
Lst.sort (reverse=true) # Descending Reverse=true
Print (LST)

LST = [' Simon blowing Snow ', ' flower full floor ', ' clan ', ' Sagong pick star ']
Lst.reverse () # Flip, the elements in the list are inverted output
Print (LST)
Print (LST) #4 the length of the list is 4


Meta-group
Print ((1+3))
Print ((3))
Tu = (3,) #元组中如果只有一个元素. Need to write one in parentheses,
Tu = tuple () # Empty tuple
Print (Type (TU))

Tu = ("RMB", "USD", "GBP", "Euro")
Tu.append ("haha")
Tu[0] = "yen" # Not allowed to modify
del Tu[2] # Delete also not

Print (tu[2]) # index can be used
Print (Tu[::2])

For El in Tu:
Print (EL)

The first layer of a tuple cannot be assigned. Internal elements are not required
Tu = (1, "Hello", "How is You?", "aux", ["Geli"])
s = Tu[3].upper ()

Print (s)

Range
Range () is an iterative object that can be used for loop
1. Range (n) 0-n-1
For I in range (10):
Print (i)
Range (m, n) #m-n-1
For I in Range (1,10):
Print (i)
3. Range (M,N,Q) m--n-1 each q take one
For I in Range (1,10,3):
Print (i)

For I in range (100, 90,-1):
Print (i)
0 1 2 3 4 5
LST = ["casserole", "Steamed bread", "rice bowls", "knife noodles", "Big Twist", "Big Pancake"]
Gets the index to the list. After getting the index. can get the element
For I in range (len (LST)):
Print (i) # I is the index of the LST
Print (Lst[i])
For El in LST: # (el = element, meaning that each element in the output list is iterated)
Print (EL)

Love Python, love to learn

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.