Lists and dictionaries
mutable data types in Python are: List and dictionary immutable types: numbers, strings, tuples speak lists and dictionaries today
A. List1. Concept:
Variables: Use variables to store data, but variable store data can only store one data at a time
Question: What do I do if I want to store multiple data at once?
#需求: Store 5 People's age, ask for an average of
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 ':
'] = 456Print(obj)= = "{' K1 ': 123, ' K2 ': 456}Python single-instance mode#Python Single-instance mode#1. Using the class method to implement#2. Using static fields to implementclassfoo:instance=Nonedef __init__(self,name): Self.name=name @classmethoddefget_instance (CLS):#CLS class name ifCls.instance:#If the static field instance is True ret
This article mainly introduces the implementation of the python dictionary sorting method. The example analyzes the skills related to the Python dictionary sorting. If you need it, you can refer to the example in this article to analyze the python
This article mainly introduces the basics of python, including file input and output, built-in types, dictionary operations, and other usage methods.
I. variables and expressions
The code is as follows:
>>> 1 + 12>>> Print 'Hello world'Hello world>>> X = 1>>> Y = 2>>> X + y3
Python is a strongly typed language and
In-depth Python (1): dictionary sorting about sort (), reversed (), sorted (), reversedsorted
Http://www.cnblogs.com/BeginMan/p/3193081.html
I. Sorting of Python
1. reversed ()
This is easy to understand. The reversed clause is reverse.
print list(reversed(['dream','a','have','I']))#['I', 'have', 'a', 'dream']
2. Conf
If you have any questions about how to create a Python dictionary and how to access the values in the dictionary, you can browse our article, after reading this article, I hope you will learn something from it. The following describes the specific content of this article.
Create a Python
的键值对个数7. Member test: ' A ' in dic #测试键 ' A ' is in the dictionary, if it returns true8. Traverse the dictionary:(1) Press key to traverse:For key in Dic.keys ():Print (key)(2) Traverse by value:For value in Dic.values ():Print (value)(3) Key-value pair traversal:For item in Dic.items ():Print (item)(4) Traversing by E
Python intensive training notes (6)-keep the dictionary in order and enhance python Training
The python dictionary is a very convenient data structure. With it, we can easily find his score, ranking, and other values based on the name (key ), instead of traversing the entir
1. String manipulationThe string can be evaluated by subscript, but because the string is an immutable variable, the value cannot be modified by subscript.str = ' Lily Terry Mark 'Name[0] #获取第1个字符串值Name[0:7] #获取第1 The string value of the ~Name[:7] #缺省开始位置, the default value starts from the 1th elementName[0:] #缺省结束位置, default to end of String endThe string contains the judgment operator: in, not in, is' Lil
': ' v1 ', ' K2 ': ' v2 ', ' K3 ': ' V3 '}Dic.pop (' K5 ')Print (DIC)7. Please get the value of ' K2 ' in the dictionarydic={' K1 ': ' v1 ', ' K2 ': ' v2 ', ' K3 ': ' V3 '}Dic.get (' K2 ')Print (Dic.get (' K2 '))8. Please get the value of ' K6 ' in the dictionary, if the key ' K6 ' does not exist, do not error, and let it return nonedic={' K1 ': ' v1 ', ' K2 ': ' v2 ', ' K3 ': ' V3 '}Dic.get (' K6 ')Print
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
Obtain the value and pythonvalue of a key when the python dictionary is nested.
Recently, a test program that writes an interface using python used a parsing dictionary to obtain the value of a key. Because the dictionary format returned by multiple interfaces is not fixed,
This article mainly introduced the Python dictionary Sort implementation method, the example analyzes the Python dictionary sorting correlation skill, needs the friend to refer to the next
This paper analyzes the method of Python dictio
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 python tu
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.