程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Let the python fly: image understanding python lists and tuples, dictionary, collection, operator

編輯:Python

Day03 Eight quit war descended from
Pig eight quit to guard the worse,One day see the seed.Pig eight quit of descent of the goddess of the moon sister to do,Very angry.於是,Pig eight quit to beat up the seed.Seed by this sudden rise of pig scared,So hurry run away,Finally at the high table.
Seed first see a a large table suspended in mid-air,One end of the table with a balloon,Which table name
(列表(list)特點:有序的(有索引、Is consistent with the definition and display order)、可變的(Can alter the content of element also can automatically(擴縮)容)、可重復的、You can store any data type element).Table standing column on all kinds of people,The arabs,With Europe and the United States,And meatballs、字典、大餅、Futon in the queue.Some people also like two peas in a pod.於是,Seed just pretend as if nothing has occurredly hide behind a futon(append(obj):將obj元素追加到列表的末尾).Pig eight quit to not arrive,His descendants found hidden in a queue at a glance,所以,Eight quit called the flying carpet,Flying carpet soon according to the number under the table lock the position of seed(1).To obtain a list element name with the subscript for --> 例如:lt[0],lt[-1]),And came to the seed above,The seed suction to the carpet,And left an Arab(2).設置元素(和str有區別)Name list with the subscript = … --> 例如:lt[4] = “武大郎”).Seed surprised,But soon escape,And in the cloned several big table(對於*操作而言:Recur to the elements in the listn次,With a new list of return),With the cross linked together(對於+操作而言:Will combine both the elements in the list of objects to a new list to return),Declared war on pig eight quit.Pig eight quit to have a look at each other a hard-hitting,So the stratagem to mind,He sent a pig with a broom,Quietly came to the descendants of the queue behind the most,Then forward swept away,Queue disappeared,Leaving only an empty table suspended in mid-air(clear():清空列表,Element didn't,A list of objects in).Descended from a look,Not only his anger in zhongshan,Picked up a machete to the queue of pig eight quit to,Some people were broadsword direct cut disappeared,Some tables are sword cut it(delKeyword matching list object/元素使用.目的:Recycling list object,Recycling of element content).Pig eight quit a see seed lost his mind,So hurriedly sent greater flying carpet to descendants of the interception of soldiers in the queue(列表的切片操作:The format and characteristics andstr一模一樣…).Seed a look not good,慌忙逃竄,And challenged pig eight quit to say fight again in the afternoon.
Eight quit won descendants,Happy to eat beef meatball string.But he also worry about,Beat a descendant of the team's makeshift,人心渙散,說變就變,It,Must want to set up their own team.Eight quit looking at the hands of the beef string,恍然大悟.He put the beef meatball string become big like a table,Beef meatball also standing soldiers,所不同的是,Soldiers on the beef meatball determined,不會改變(元組特點:有序的(有索引、Is consistent with the definition and display order)、不可變的(和str一樣理解)、可重復的、You can store any data type element),And not from the team behind the most to join in.Broom simply doesn't work for them(思考:Tuples have similar to the listappend或者clear函數?沒有,因為append和clearThis kind of function change is the inside of the container object element content,This conflict and immutable).而且,他們非常團結,Sword can cut beef balls,Can't cut down their a(delKeyword matching tuple objects using.目的:Recycling the tuple objects,But you can't recycle any one element).They listen to the flying carpet and eight quit.Eight quit found only a soldier on the some balls,Give him with a dog(元祖名 = (值1,)
【注意】:Define the tuples and only one element,To add a comma after the element display).
Have your own team,Eight quit pleasantly surprised.But a real powerful is a think tank.So master took out to give him a dictionary(字典特點:無序性(沒有索引,通過鍵找值)、可變的數據類型(值可變、鍵不可變)),將其變大,Then a net world division,Put them to the dictionary(字典的結構:鍵值對組合 --> key-value對象).These divisions each people all have own nickname(鍵(key):唯一性(不可重復)、不可變的數據類型(例如:listCannot as a key)),且各不相同.If you have the same nickname,Was later replaced by(In defining a dictionary object if a duplicate key,Keep the keys at the same time,Will the latter value cover at the front of the).If there is no division name,Can be directly to its and his entourage added(In the process of adding a new key/value pair,If the original dictionary objects without this button,Then it will be the keys to join together in,稱為一個元素dic2 = {“name”:“韓梅梅”,“age”:23,“height”:165.0,“name”:“李雷”} dic2[‘weight’] = 120).They also can arbitrarily choose after(值(value):沒有任何要求,可以是任何類型的數據,Even can be repeated).Due to the division it,Clean broom to pick the dictionary(clear():清空字典元素,Keep an empty dictionary object).同樣,Even a broadsword strategist hacked to death,Put the dictionary cutting(和關鍵字del配合使用:目的:Recycling key combination,Or the whole dictionary object).If you are looking for a military adviser(For the lookup value through the key can be divided into the following two ways to realize:),可以通過兩種方法,One is direct call its nickname(方式一:字典名[鍵名] 如果鍵不存在,報錯;出現KeyError類型的異常),當然,May no one reply.Another is to use a pair of big hands holding it out,If people are not in,Hand can tell you is empty(方式二:字典嗎.get(鍵名) 如果鍵不存在,不會報錯,Will return to the program aNone值;This way is safe/友好(更加好用)).
Eight quit after rectification good dictionary camp,Began to eat pie.A division is ran and told eight quit,Our current team mobility is poor,Need to build a team protean and can well together.Eight quit looking at the hands of the pie(集合(set)
特點:無序性(沒有索引,Every show the effect of the different)、唯一性(不可重復)、 可變的、Only immutable data),頓時有了主意.He put the pie as carrier,Soldiers are allowed to wander at will in the pie,But each soldier is the only(使用場景:在實際開發過程中,Often used in the data is to heavy(過濾)).Pie with pie can overlap between(&:取交集),可以聯合(|:取並集),可以相減(-:取差集),Can joint minus overlap part first(^:Set to abandon intersection with the first part).但是,Broom and machetes can work on it(clear():清空集合,Keep the shell .和關鍵字del配合使用: 目的:Recycling collection elements,Or recycle the whole collection objects).If you want to fire a soldier,Can pass below saw a small round cakes,The small round cakes will be the removal of the soldier(思考:刪除"貂蟬"這個數據,To do so?可以使用remove(obj)函數來實現…).如果需要,Pie list can also be converted into soldiers(將集合轉換為列表 --> 使用轉換函數list()).
Eight quit relieved after lunch,Static, such as seed come in the afternoon.午後時分,Seed with a large number of teams rushed to the.Pig eight quit to calm.可是,Heaven now enacted new regulations,One-on-one hit seven process to go.The first event is(算數運算符:符號:+ - * / %(取余、取模) //(取整) **(開方))算數,加減乘除,取余,取整,開方.Eight quit lost start.
The second project is than weight(比較運算符:符號:> >= < <= ==(全等) !=(不等於).特點:The results of the comparison operation must be a Boolean value(True/False)),See who's big.Eight quit laugh,扳回一局.
The third project is to teach disciples martial arts(賦值&混合賦值運算符:The assignment operator symbol:= Compound assignment operator symbol:+= -= *= /= %=),They're going to play.Eight quit to lose...
The fourth project is logical ability compete my wife(邏輯運算符 符號:and(邏輯與,並且,去交集) 總結:and操作,Meet the characteristics of a false or false,理解為:對False敏感;or(邏輯或,或者,取並集) or操作,Meet a really namely really characteristics,理解為:對True敏感、not(邏輯非,取反).特點:On either side of the operator must be a Boolean data type,結果也是布爾型).Eight quit and seed have no wife,So the team chose a female police to compete.This one pig won.
The fifth project is chosen two soldiers to the tower of the bottom2Column on the stone steps match.Every ordinary soldiers will become a couple of kids,Have a boy,There were girls,Standing side by side column.Then comparing with the other children queue.Can get the final results calculated according to the rules of one party to win(位運算符:長處:Is the highest operator in the operation efficiency of,Direct is the underlying binary arithmetic.符號:&(按位與)、|(按位或)、^(按位異或)、<<(左移)、>>(右移)).這一把,Eight quit the loss of a good.
The sixth project to guess the undercover game(成員運算符:作用:Apply for container object judgment,結果都是布爾值;Whether an element is present in the container.符號:in / not in).Because the fifth project,Some of the other camp's children ran to the same faction,So want to pick out the small undercover.Eight quit in sun wukong's side for so long,Also learned some of the critical,At a glance and picked the other small undercover.這一把,Eight quit to win
The seventh item is Let selected small undercover with whom your choice(三元/三目運算符:格式:表達式1 if 條件表達式 else 表達式2).Eight quit and seed for each treatment,If the kids and put forward conditions meet,Let the kids can collect.Finally according to the number of children decided the outcome.
最終,Eight quit narrowly seed!撒花~


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved