The dictionary is the only type of mapping in Python. Dictionaries are mutable, unordered, variable-sized key-value mappings, sometimes called hash lists or associative arrays.Examples are below: DiC = {"Apple": 2, "orange":1} #定义一个字典 >>>
The list is mutable and can be changed by the sequence, which can hold any data type.>>> list = [] #定义一个空列表>>> list.append (1) #向列表中添加成员>>> List.count (2) #计算2在列表中出现的次数0>>> List.extend ([2, 3, 5, 4]) #向列表中添加一个列表>>> List #列表值被改变[1, 2, 3, 5, 4]>>>
The first thing you need to know about Python's read path>>> Import Sys>>> Sys.path[', '/usr/lib64/python26.zip ', '/usr/lib64/python2.6 ', '/usr/lib64/python2.6/plat-linux2 ', '/usr/lib64/python2.6/ Lib-tk ', '/usr/lib64/python2.6/lib-old ',
Python has two package management tools that encapsulate the Setuptools: easy_install and pip . Currently the official recommended use pip .Now, let's install a third-party library,--python Imaging Library, which is a very powerful tool library for
Use psutil to obtain system information in python
#! /Usr/bin/env python # coding: utf-8import psutilimport timeimport sysfrom optparse import OptionParserparser = OptionParser () parser. add_option ("-t", "-- time", dest = "time", help = "this
Python reverse ()
The reverse () method replaces the reverse list object.Syntax
The syntax of the reverse () method is as follows:
List. reverse ()
Parameters
NA
Return Value
This method does not return any value, but reverses the given
Use python to automatically modify the local gateway code sharing in Linux, and use linuxpython
#! /Usr/bin/python # auto change gateway Created By mickelfengimport osimport random, reg = 'Gateway 192.168.1. 'rand = random. randint (1, 3) test =
Briefly introduce the concept of tuples in Python and the concept of python.
Tuples are unchangeable Python object sequences. The sequence of tuples is like a list. The only difference is that the tuples cannot be changed, that is, the tuples cannot
Basic knowledge of the dictionary in Python
The dictionary is variable and can store any number of Python objects, including other container types and another container type. The dictionary includes key pairs (called projects) and their
Use the clear () method for dictionary operations in Python, pythonclear
The clear () method deletes all items in the dictionary (clear the dictionary)Syntax
The syntax of the clear () method is as follows:
Dict. clear ()
Parameters
NA
Use the fromkeys () method for dictionary operations in Python, pythonfromkeys
The fromkeys () method sets the sequence key and value to create a new dictionary.Syntax
The syntax of the fromkeys () method is as follows:
Dict. fromkeys (seq [,
In Python, use the get () method to obtain dictionary key values.
The get () method returns the value of the given key. If the key is unavailable, the default value None is returned.Syntax
The following is the syntax of the get () method:
Dict.
Use the setdefault () method for dictionary operations in Python, pythonsetdefault
The setdefault () method is similar to the get () method, but the dictionary [Key] = is set by default if the key is not already in the dictionary.Method
The
In Python, use the swapCase () method to convert the case.
The swapCase () method returns all uppercase and lowercase characters. A copy of the string is exchanged Based on uppercase and lowercase characters.Syntax
The following is the syntax of
Python zfill () method usage tutorial, pythonzfill
The zfill () method fills the left width with a zero pad string.Syntax
The syntax of the zfill () method is as follows:
Str. zfill (width)
Parameters
Width -- this is the final width of the
Usage of the title () method in Python, pythontitle
The title () method returns a copy of the string whose first character is uppercase for all words.Syntax
The syntax of the title () method is as follows:
Str. title ();
Parameters
NA
Python List. index () method usage tutorial, pythonlist. index
The return value of the index () method is obj, which appears in the list.Syntax
The syntax of the index () method is as follows:
List. index (obj)
Parameters
Obj -- this is the
Python regularly checks whether a process has been disabled.
This example describes how to regularly check whether a process is disabled in python. Share it with you for your reference. The details are as follows:
Import threadingimport timeimport
Python uses the shelve module to implement simple data storage.
This example describes how Python uses the shelve module to implement simple data storage. Share it with you for your reference. The specific analysis is as follows:
The shelve module
Python uses matplotlib to draw a rectangle in the coordinate system.
This example describes how to draw a rectangle in the coordinate system using matplotlib in Python. Share it with you for your reference. The specific implementation method is as
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