Definition of the array:Arrays: Arrays are collections of ordered objects that are used to store objects with sequential tables (note that basic data types cannot be stored, only objects can be stored). objects: Concrete implementations of ClassesAs with strings, arrays also have variables and immutable groups, and variable groups are subclasses of immutable groups, and array objects must be created before using arraysNsarray class: (Non-variable grou
tuples : Immutable listsAdvantage: security, for the definition of data, can be used tuples in tuples, because it is immutable.To create an empty tuple:Tuple1= ()To create a tuple with different types of elements:Tuple2= (1,1.1, ' good ', True,none, (All-in-all), [1,2,3,4],{1:2,3:4})Create a ganso with only one elementtuple3= (1,) Remember: Be sure to call this comma, or the system will assume that Tuple3 is an integer typeIncrease:None, because tuple
three. Dictionaries and related uses1. Dictionary definition dict{}2. Dictionary features: Dictionary is unordered, key-value key value pair form, key value is not duplicated3. Assignment of dictionaries: dicta = {Keya:valuea, Keyb:valueb, KEYC:VALUEC}4. Dictionary value: Dicta[keya] Dicta.get (Keya)5. All keys of the Dictionary: Dicta.keys () Key-value get: Dict
Today, let's look at some common uses of dictionaries in Python. As for the study of dictionaries, we should know the definition and differences of dictionaries and the characteristics of other data structures, commonly used methods of operation. All right, let's get to the business!1. Dictionary definitionsA dictionar
Dictionaries
Objects that can store multiple elements become containers, and the list and tuple mentioned above belong to the container class, which introduces a new container: a dictionary.
Basic conceptsCommon basic methods for creating dictionaries:
dic={' key ': value, ' key ': value, ' key ': Value ...}
The dictionary contains two parts, a key and a value, where the key is usually a string, or it can
Getting started with Python: 9 dictionaries 1. definition of dictionaries
The feature of the dictionary is that the icon of the dictionary is curly braces, and the elements in the dictionary use key-value pairs. A key-value pair is used as a data item.
2. create a dictionary
(1) definition
Dict1 = {'Li Ning ': 'Everyt
This article corresponds to exercise 39 dictionaries and cute dictionaries.
# Encoding: UTF-8 # differences between the list and dictionary # list thing = ['name', 1, 'age', 'ad ', 'sex'] print thing [1] # print thing ['name'] # An error is returned. The list can only be accessed through an integer: TypeError: list indices must be integers, not strstuff = {'name': 'Tom ', 'age': '28', '1 ': 'test'} print
= (1,2,3,4,5)1 in X= True6 in X= Falsefour, bif tuple related built-in method1. Tuple ( Converts an iterative object into a tupleTuple (' Hello ')= = (' H ', ' e ', ' l ', ' l ', ' o ')2, min,max,len,sum:x= (1,2,3,4,5)Min (x)=>1Max (x)=>5Len (x)=>5Sum (x)=>15V. "variable" tuple of PythonWe saw in the front that the tuple cannot be modified once it is Created. now, let's look at a "mutable" tuple:>>> t = (' a ', ' b ', [' a ', ' b '])Notice that T has 3 elements:' A ', ' B ' and a list:[' a ',
Meta-groupA python tuple is similar to a list, except that the elements of a tuple cannot be modified .Tuples use parentheses, and the list uses square brackets.Tuple creation is simple, just add elements in parentheses and separate them with commas.tp= (The'a','b')' Hello World ' # this definition is str type b = ('helloWorld') # when defining tuples, if there is only one element, then the type of B is str C = ('helloworld',)print(type (c))Tuples
The differences between tuples, lists, and dictionaries in PythonIn Python, there are 3 built-in data structures: lists, tuples, and dictionaries.The list symbol is the [] bracketTuples are () bracketThe dictionary is {} curly braces1. ListA list is a data structure that handles a set of ordered items , that is, you can store a sequence of items in a list. Items in the list. The items in the list should be enclosed in square brackets so that Python kn
keep the data before and after it is modified?1 Copying a copy in memory③ Dictionary common Method-------get (), get a value corresponding to a key, if the key does not exist, return none, you can also specify to return other results, the Get method can avoid the key does not exist when the error is returned>>> name_dict{' Tony ': +, ' Alex ': ' Eric ': 26}>>> name_dict.get (' Alex ')22>>> name_dict[' Alex ']22>>> name_dict.get (' Eric ')26>>> name_dict.get (' Susan ')>>> print Name_dict.get (
Common dictionaries for Python are denoted by {} curly braces.Dict1 = {key1:value1, key2:value2}Each key value of the dictionary is key:value corresponding to the colon, and each key value is separated by commasA dictionary definition method, such asA={name:huang}Print aName is Key,huang is value,B=dict (a=1,b=2)A, B is key,1,2 is valuec= ([' Name ': ' Huang '), (' Age ': ' 20 ')])This means that you can al
? Python provides a concise way to exchange data: x, y = y,x so that the values of the × and Y are interchangeable.? variable data type: List? Immutable data types: numbers, strings, tuples? sequence data type: string, list, tuple? unordered data types: numbers, dictionariestuples : A list with a magic spellTuples and lists differ in that tuples are immutable data types, and he does not have the means to append and store data more securelyFirst, create:Tu = (1,2,3,4)Note: A single tuple
Constant definition rule: constant meaning is not changed; Constant definition name is all uppercase;such as: mysql_connection= ' 192.168.1.1 'Pyc:python generated translation files that enable the computer to recognize the Python language;Syntax and use of the list:List parameter insertion syntax: Name.insert (2, ' Minggou ')NAME[1] = "Wangminglong"---> Modify the contents of the corresponding field in the
to sort the keys in the dictionary, and the properties of the object cannot be sorted in JavaScript . But remember, JavaScript is all objects, and arrays are objects.Start by defining the dictionary class with the following code: function Dictionary () { thisnew Array (); }First, define the Add () method, which accepts two parameters, keys, and values. The key is the index of the value in the dictionary. The code is as follows: function Add (key, value) { this. Datastore
dictionaryDict.pop ()Dict.get (' key ') gets the value of a key from the dictionaryDict.has_key (' key ')CollectionThe collection is divided into mutable set (set) and immutable set (Frozenset)Set hash, Frozenset non-hash (infrequently used)Set is a non-repeating set of elements that support Union (union), intersection (intersection), difference (differential set), and sysmmetric difference (symmetric difference sets), and other mathematical operations1. De
One, 1: ganso: Tuple in Python, Ganso is also a list, and the difference between it and list is that the elements in the list can be modified, and the elements in the meta-ancestor cannot be modified.2: Definition of Ganso: with parentheses ()Second, 1. Dictionary dictionary full Dictionary, Dictionary is the advantage of dictionary in the Key-value format: Find elements fast,2. Dictionary definition: using
Java and Python use Youdao dictionaries to make word-search scriptsLet's take a look at the results in two pictures.Java's:Python's:Today's whim, want to do a look up the words of things, hurriedly to Youdao dictionary official website looked, originally we want to query the word is embedded in the page address to Youdao dictionary, and then the page result is we need word interpretation, so this thing need technical knowledge only:
Regular e
ListThe list is made up of elements that are arranged in a particular sequence of sequences. You can add strings, numbers, dictionaries, and so on to the list. The list is also marked with the default starting from 0. L = [' A ', ' B ', ' C ', ' d ', ' e ', [+/--] Print (Type (l)) Print (dir (l)) Run Result: [' __add__ ', ' __class__ ', ' __contains__ ', ' __delattr__ ', ' __delitem__ ', ' __ delslice__ ', ' __doc__ ', ' __eq__ ', ' __format
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.