Author: vamei Source: http://www.cnblogs.com/vamei welcome reprint, please also keep this statement.
The Python built-in (built-in) function is created with the running of the python interpreter. In pythonProgramYou can call these functions at any time without defining them. The most common built-in functions are:
Print ("Hello world! ")
In the
;> C{' names ': [' Alfred ', ' Bertrand ', ' Clive ']}>>> D{' names ': [' Alfred ', ' Bertrand ', ' Clive ']}>>> DC{' names ': [' Alfred ', ' Bertrand ']}3. Fromkeys Create a new dictionary with the given key>>> {}.fromkeys ([' Name ', ' age ']){' Age ': none, ' Name ': none}>>> Dict.fromkeys ([' Name ', ' age ']){' Age ': none, ' Name ': none}>>> Dict.fromkeys ([' Name ', ' age '], ' (unkown) '){' Age ': ' (unkown) ', ' Name ': ' (unkown) '}4, get, a
Original website: http://www.iplaypython.com/jinjie/jj116.htmlLike other python built-in data types, dictionary dict also has some practical ways to do it. Here we are talking about the dictionary deletion method : Clear (), pop (), and Popitem (), the three methods have different functions, the operation method and the return value are not the same. Next, look a
This article describes how to solve errors caused by changing elements during dictionary traversal in Python. it discusses and solves the problem of dictionarychangedsizeduringiteration after adding or deleting elements, for more information about how to traverse the dictionary in Python, see:
Script:
#!/usr/bin/
1. IntroductionA dictionary is a mapping data type in Python, consisting of a key-value (Key-value) pair.Keys: Almost all types of Python objects can be used as keys, but they are usually most commonly used in numbers or strings.Value: Can be any type of Python object.The dictionar
Common definition methods for Python dictionaries
Define a dictionary directlyDict1 = {' x ': 1, ' Y ': 2, ' Z ': 3}
Define a dictionary using the Dict methodDict2 = Dict (X=1, y=2, z=3)
Define a dictionary using the Dict methodDict3 = Dict ((' x ', 1), (' Y ', 2), (' Z ', 3)))
Dict built-in method
The advanced tutorial further expands the basic tutorial to illustrate the details of Python. I hope you will have a more comprehensive understanding of Python after the advanced tutorial. The basic tutorial introduces basic concepts, especially objects and classes.
The advanced tutorial further expands the basic tutorial to illustrate the details of Python. I h
= Set1.difference (Set2)#difference = minus public part-Set1-set2 Print(set3) Set3= Set1.symmetric_difference (Set2)#symmetry difference = set-intersection ^ Set1 ^ Set2 Print(SET3) forValinchSet2:Print(val)Print(Set2.pop ())#you can get one, there's no guarantee what you got.
element to the dictionary:>>>dic[' Lilei '] = 99>>>print DICHere, we refer to a new key and give it the corresponding value.Circular invocation of dictionary elementsDIC = {'lilei'Lily'sam' Tom': All -in-in dic :Print Dic[key]In the loop, each key of the dict is extracted and given to the key variable.With the res
second feature in the above Code is more elegant, however, similar to dict functions, when a key is a variable, only the literal value is used.1.5 delete a dictionary
You can call the built-in Python keyword del to delete a key value.
>>> info = dict(name='cold', blog='linuxzen.com')>>> info{'blog': 'linuxzen.com', 'name': 'cold'}>>> del info['name']>>> info{'blog': 'linuxzen.com'}
You can also use the pop
, the result of the compilation is saved in the Pycodeobject in memory, and when the Python program finishes running, the Python interpreter writes Pycodeobject back to the PYc file.When the Python program runs for the second time, the program will first look for the PYc file on the hard disk, and if it is found, load it directly or repeat the process.So we shoul
:
Copy Code code as follows:
>>> x=1
>>> y= (x=x+1)
Syntaxerror:invalid syntaxWith #! The beginning is called the organization line, which tells you which interpreter the Linux/unix system should run when you execute your program. For example: #!/usr/bin/python
The beginning of a # is called a comment line.
Second, conditional statements
Control Flow statement: Any conditional expression can be established by using the Or,
Python has three built-in data structures: list, ancestor, and Dictionary. This article introduces these three data structures and provides examples, let's take a closer look at the differences between the three.
1. list)
List is the data structure that processes a group of ordered projects. you can store a series project in a list.
The items in the list should be included in square brackets so that
analyze the figure above. Except the root node, each subnode stores only one character. Go and golang share the go prefix. php, perl, and python only share the p prefix. To sort the dictionary, the characters stored on each layer of nodes are stored in alphabetical order (this is related to the Traversal method ). Let's take a look at how to sort a single character in the
the user selects the product, checks whether the balance is enough, is enough directly to deduct the paragraph, is not enough to remindCan exit at any time, print purchased goods and balances when exiting
#购物车练习题
Shoplist = [1, iphone, 6000], [2, Mac Pro, 12000], [3, "ipad Air", 8000], [4, "Chicken", 5], [5, "eggs", +], [6, "Bi" Ke ", 500]]Mall = []salary = Int (input ("Please input your Salary:"))While True:For I in range (0, Len (shoplist)):
The derivation of comprehensions (also known as analytic) is a unique feature of Python. Derivation is the structure of another new data series that can be built from one data series.
List-derived
Dictionary (dict) derivation formula
Set (set) derivation
List derivation one, use [] to generate listBasic format for inch if the condition]expression# list generates an element expr
the value of key is the set typec['a'].add (1) c['a'].add (2) c['a'].add (2) c['b'].add (4)Print('the value of key is a dictionary of the list type:', D)Print('the value of key is a dictionary of the set type:'C>>> ================================ RESTART ================================>>>the value of key is a
I want to explain the print of Python and learn pythonprint.
Eval ()
Let's take a look at this stuff before we print it. It is not useless, because it may be used in some cases.
Copy codeThe Code is as follows:>>> Help (eval) # This is a rare concept. If you don't understand how to use it, use this document.
Help on built-in function eval in module _ builtin __:
The dictionary is the only built-in mapping type in Python. The values in the dictionary are not in a special order, but are stored in a specific key.
A key can be a number, a string, or even a tuple.
1. Creating and Using dictionaries
Dictionaries can be created in the following ways:
Copy CodeThe code is as follows:
Phonebook = {' Alice ': ' 2341 ', ' Beth ':
to choose a hash key is because its value cannot be changed.Numbers and strings can be used as a dictionary key, tuples are immutable but may not be immutable, so the use of tuples to make valid keys must be restricted: if the metaOnly immutable parameters such as numbers and strings can be included in a group as valid keys in a dictionary.
Example:# VI userpw.py
#!/usr/bin/env
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.