Python basics, including lists, tuples, dictionaries, strings, set sets, while loops, for loops, operators.

Source: Internet
Author: User
Tags arithmetic operators bitwise bitwise operators logical operators shallow copy install pandas

     1.continue: Jumping out of a loop, making the next loop      2.break jumping out of the loop      3. Constant (all uppercase) NAME = CJK   Generally changed the third-party libraries that will make mistakes      4.python, and then install and import them first. Install module: PIP command For example: Pip install pandas     5.os.system (command) on Linux and window line      6.res  = os.popen (' ipconfig '). Read ()     &NBSP;7.PYC is a thing.       8.sys.exit () jump out of all       9, list: name =  [' Minglong ', ' Minghu ', ' + ', ' Jack ']  & nbsp     Name[0]   is   ' Minglong '  name[-1]   is ' Jack ' name[:2] is from the beginning to the Minghu never get the Last, Name[2:] From 32 to the most After     Modify element: name[0] = ' Wangminglong '  name[0][0]   is ' m ', take out one of the values in the element     insert: Name.insert (2, ', Minggou ') is added minggou    append to Minghu: Name.append (' xiaoming ') added xiaoming    Delete at the end: Name.remove (' Xiaoming ') directly delete xiaoming or  del  name[0:2] will be the first to the second delete, Name.pop (0) Delete the first number and return this element.    step: name[::2] Step is 2, take one element at a intervals     check: 32 in the name to determine if the second nAme list    name.count (' Minglong '): Lookup for Name list has several ' Minglong ' returns of 1.    name.index (' Minglong '); Find the index of Minglong, and return 0. If more than one Minglong returns the index of the first found result.    name2 = [' CJK ', ' Xiaoqiang ',2,4]   name.extend (name2): Append name2 to the name list     Name.reverse (): Sorts the elements in turn.    name.cope () shallow copy. There is a deepcopy in the import copy module which is a deep copy. The difference is that if a list is nested, the list in the nested lists will be changed with the original list, while the deep copy is a complete clone of the list, and the 2 are independent of each other.    len (name): The length of the list, here is the number of elements.  7.26   10, tuple: Name = (1, ' qqq ', ')   read-only list.       Name.count and Name.index on 2 apps.           11. String:      Remove blank strip:name = input (' username: '), if name.strip () = = ' Cao ': print (' Welcome ') defaults to remove whitespace characters (including ' \ n ', ' \ R ',   ' \ t ',   ').     Split split:names = ' Cao, Cjk,alex '   name2 = Names.split (', ') then name2 = [' Cao ', ' CJK ', ' Alex '] splits the string into lists as ', '.      join The elements in the list into a string: Name3 = ' | '. Join (name2) Name3 = ' Cao|cjk|alex '       Determine if there are spaces: name = ' Cao Fa ', print (' in name ')   return true     str.format (): msg = ' Hello {name} ' it ' s been {time] days since I saw you ' MSG2 = Msg.format (name = ' CJK ', time = 30) or msg = ' Hello {0} dddd{1} ' MSG2 = Msg.format (' Alex ', 33) is also OK. Dic1 = {' name ': ' Alex ', ' age ': +   MSG2 = Msg.format (**dic1) or list1 = [' Alex ', ' +]   MSG2 = Msg.format (*list1) is passed All the elements in the List1.            String indexes are the same as slices and lists: name = ' Caofajia ' name[0] = ' C '       Str.center (): As name = ' Cao ', Name.center (40, '-') generates '--------Cao--------' A total of 40 characters centered on the CAO and complete with '-'. &NBSP;12, operators      12.1, arithmetic operators                +      -       *       /      //     %        **     12.2, relational operators           &NBsp;  <       <=      >        >=      ==     !=     12.3, Logical operators              and     or       not     12.4, bitwise operators              Inverse (~), Bitwise AND (&), or (|) and XOR (^) and left (<<) and right Shift (>>)      12.5   Assignment and increment assignment operators:              +=     -=      *=& nbsp;    /=     %=      **=              <<=     >>=      &=      ^=      |=&NBSP;&NBsp;      12.6  Supplement:            Plural cannot use relational operators       &NBSP ; The     bitwise operator can only be used for integer type 13. Dead Loop:          while true:print (' Nihao ') 14. Dictionary: id_db = {     12: {            ' name ': ' Cao ', ' Age ': ' addr ': ' Shandong '          },& nbsp    13:{            ' name ': ' Alex ', ' age ': one, ' addr ': ' Dongbei '       & nbsp  }}         : id_db[12] The value corresponding to key 12 is {' name ': ' Cao ', ' Age ': ' addr ': ' Shandong '}          change: id_db[12][' name ' = ' CJK ' Here changes ' Cao ' to ' CJK '         ' Delete: Id-db[12].pop (' addr ') delete the addr corresponding key value.         add: id_db[13][' qq_of_wife ' = 2134, added ' qq_of_wife:2134.     id_ ' in the dictionary below 13 Db.get (): The advantage is that if the key does not exist, return directly to none.     id_db.update (): Dict1 = {       13:{' name ': ' Shanpao ', ' age ':13           }       14:{' name ': ' Dashanpao ', ' age ' :21           }} if Id_db.update (Dict1)   id_db will change to add 14 and Dict1 13 covers id_db in 13.&N Bsp      id_db.items (): Generally not used in large-scale dictionaries, because it is inefficient to convert dictionaries into list forms.        id_db.values (): Displays a list of values.        id_db.keys (): Displays a list of key components.       Judgment key is not in the dictionary: db_db returns True.       Id_db.setdefault () and Id_db.fromkeys () are not generally used ...       Loop: for K, V in Id_db.items (): This is inefficient because you want to dict the list.                 for key in id_db:     general Use this.                          print (Key,id_db[key])   &NBS P  15. Set: unordered, non-repeating collection of sequences.             Presentation method: 1. S1 = {11,22,33} 2. Set ([11,22,33]) is also OK, actually executes a for loop to generate {11,22,33}.         &NBSP   Add Add:s1.add (44) Adds an element that is not in the set. If you repeat, do not add.             Clear and copy with list.           &NBSP;DIFFERENCE:S2 = {22,33,44} then s1.difference (S2) indicates that S1 exists in S2 and does not exist, generating a new object {11}.            symmetric_ difference:s1.symmetric_difference (S2) generate new {11,44}    & nbsp      difference_update:s1.difference_update (S2) changes the S1 to {11}. As long as there is an update in the back, the previous object S1 updated.             Remove: 1.dicard  s1.dicard (11) Remove 11,s1.dicard (11221) elements that do not exist do not error.                      2.remove  s1.remove (1123130) remove non-existent error &NB Sp                    3. Pop ()  s1.pop () randomly removes and generates a removed object, generally s3 = S1.pop ().             intersection:s1.intersection (S2) to intersect the object {22,33} that generated the row.             Union:  s1.union (S2)       &NBSp     Bulk Add: S1.update ([111,222,333,444]) update accepts objects that can be iterated, such as List,str,tuple.

Python basics, including lists, tuples, dictionaries, strings, set sets, while loops, for loops, operators.

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.