Strings and encodings
Character
Ascii
Unicode
UTF-8
A
1000001
00000000 01000001
1000001
In
X
01001110 00101101
11100100 10111000 10101101
FormattingIn Python, the format used is consistent with the C language and is implemented as a%, for example:>>> ' Hello,%s '% ' world '' Hello, World '>>> ' Hi,%s, you have $%d. '% (' Michael ', 1000000)' Hi, Micha
I. Basic data types
Integer: intString: str (note: \ t equals a TAB key)Boolean value: BOOLListing: Listlist with []Ganso: TupleFor Ganso ()Dictionary: Dict
Note: All data types exist in the class column that you want to correspond to, Ganso and list functions, the list can be modified, the meta-ancestor cannot be modified.
Two. Dictionary all data types:
Common operations:
Index, new, delete, key, value, key-value pair, loop, length
Class
Python dict dictionary and some examples of value assignment reference (detailed description), pythondict
Recently, I am working on a very large database that needs to be searched by numerical value. So I thought of the dictionary in python, and I have never used dict.
List and tuple are the most commonly used)
I have
How to compile a Python script to convert a sqlAlchemy object to dict
This article mainly introduces how to compile a Python script to convert the sqlAlchemy object to dict. It mainly constructs a conversion method based on the Python model class. For more information, see
W
How to sort the Dict type key (keys) (Python 2.4 or later):Mydict = {'Carl': 40, 'Alan': 2, 'Bob': 1, 'Danny': 3} forKeyinchSorted (Mydict.iterkeys ()):Print "%s:%s"% (key, Mydict[key])Results:Alan:213Excerpt from Python faq:http://www.python.org/doc/faq/general/#why-doesn-t-list-sort-return-the-sorted-list.If you sort by key (keys) in
The structure of a PHP-like array in Python has list,tuple,dict and set, where list, tuple, and set are similar to the PHP indexed array, and dict is similar to the associative array of PHP,
dict:
The structure of the dict represents a mapping relationship, similar to a PH
can be queried either by the Get method or by key directly, but if the key does not exist, the error will be given, and get will give noneYou can add or change dict,dict (' key ') directly =valueYou can use the Pop method Dict.pop (Key[,default]) to delete the elements within the dict with the key value and return the value corresponding to the deleted key. If k
This paper analyzes the application of dict,set,list,tuple in Python and its corresponding examples, which can help readers grasp the concept and principle. Specific as follows:
1. Dictionary (dict)
Dict surrounded by {}Dict.keys (), Dict.values (), Dict.items ()Hash (obj) returns the hash value of obj if it returns a
Python built-in dictionary: dict support, Dict full name dictionary, also known as map in other languages, using key-value (Key-value) storage, with extremely fast search speedSet is similar to Dict and is a set of keys, but does not store value. Because key cannot be duplicated, there is no duplicate key in set.Dictio
Here is the "dictionary dict" and "Set set" types, first of all, to understand, for Python, the standard hashing mechanism is provided by the hash function, for the call to a __hash__ method:>>> Hash (56>>>) hash ("I like Python")-4698211515002810579The mechanism for this standard hashing is often used for the implementation of the dictionary type (
before index
Sort () to list remember orderL.sort (Cmp=none, Key=none, Reverse=false)--stable sort in place;CMP (x, y)-1, 0, 1
Reverse () reversalL.reverse ()--Reverse *in place*
Pop () deletes and returns the element value of the specified subscript, without specifying the default deletion of the lastL.pop ([index]), item-Remove and return item at index (default last).
Extend () extending the list by appending iteration elementsExtend list by appending elements from the iterabl
Python dictionary dict by value in keyAs we all know, the biggest advantage of dictionary dict is that it is very fast to find or insert, and does not want to list lists, as key increases more and more complex. But Dict need to occupy a large amount of memory space, in other words, the dictionary
The code is as follows
Copy Code
#!/usr/bin/env python#-*-Encoding:utf-8-*-Dict2 = {}A = ' a 'Dict2.setdefault (a,1) #加入一个键和值 a,1A = ' B 'Dict2.setdefault (a,1) #加入一个键和值 b,1A = ' a 'Dict2.setdefault (a,2) #加入一个键和值 a,1, the resulting duplicate key cannot be repeated by adding {' A ': 1, ' B ': 1}Print Dict2#遍历key和valueFor key in Dict2.keys ():print ' key ', key, ' value ', Dict2[key]Print Dict2.has_key (' name ') #判断是否含有一个key
Dict (dictionary)Python built-in dictionary: dict support, Dict full name dictionary, in other languages also known as map, using key-value (Key-value) storage, with a very fast search speed.Compared with list, Dict has the following features:
The speed of finding a
This example describes how Python accesses dictionary (dict) data using the dot operator. Share to everyone for your reference. The specific analysis is as follows:
The usual way to access the dictionary using a method similar to: dict[' name '] is more convenient if it can be accessed through Dict.name, the code below customizes a class that provides this appr
This article illustrates how Python uses the dot operator to access dictionary (dict) data. Share to everyone for your reference. The specific analysis is as follows:
The usual access dictionary uses something like: dict[' name ', and if it's easier to access through Dict.name, the following code customizes a class to provide this method.
Class Dottabledict
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.