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 ',
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
Reference and replication in python, and python reference and ReplicationObject Reference
>>> A = [100,] >>> B = a >>> B is aTrue >>> B [2] =->>> B [1, 2,-100, 4] >>> a [1, 2,-100, 4]
AAndBReferences the same object. Modifying one of them will
Python reads images from the network and processes them directly,
This example describes how python reads images from the network and processes them directly. Share it with you for your reference. The specific implementation method is as follows:
Python3 implements the method of reading the specified row from the file,
This example describes how Python3 can read a specified row from a file. Share it with you for your reference. The specific implementation method is as follows:
# The
Implementation of python screen capture in linux
This article describes how to implement python screen capture in linux. Share it with you for your reference. The specific implementation code is as follows:
#!/usr/bin/python'''by zevolo, 2012.12.20''
Python checks whether an object is a string type.
Purpose
Test whether an object is a string.
Method
The base class of the Python string is basestring, including the str and unicode types. Generally, the following methods can be used:Copy codeThe
Five methods for processing one character each time in Python, python5
Purpose
Each character of a string is processed. In fact, each character (Char) is a one-character string.
Method
1. Use the built-in function list ()
Copy codeThe Code is as
Python string character-by-character or word-by-word inversion method, python string
Purpose
It is interesting to reverse a string by character or word.
Method
Let's first look at the character-by-character inversion. The first method is to set the
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 =
Usage of the copy () method in Python, pythoncopy
The copy () method returns the shortest copy of the dictionary.Syntax
The syntax of the copy () method is as follows:
Dict. copy ()
Parameters
NA
Return Value
This method returns the
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, the keys () method is used to return the dictionary key.
The keys () method returns a list of all available keys in the dictionary.Syntax
The syntax of the keys () method is as follows:
Dict. keys ()
Parameters
NA
Return Value
In Python, use the has_key () method to find whether the key exists.
If the given key is available in the dictionary, the has_key () method returns true; otherwise, false.Syntax
The syntax of the has_key () method is as follows:
Dict. has_key
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
Common python libraries
Collection LibraryCollection
In some cases, Counter is very useful. If you have been to Facebook HackerCup for the past year, you can even find something useful.
From collections import Counter
Print Counter (hello)
Use of the maketrans () method in Python2.x, python2.xmaketrans
The string intab returned by the maketrans () method maps each character to a conversion table with the same position as the character string outtab. The table is then passed to the
For details about the rfind () method in Python, pythonrfind
The rfind () method returns the last index or-1 found in the sub-str. If no such index exists, you can select to restrict the search string [beg: end].Syntax
The syntax of the rfind ()
Use of the rindex () method for string operations in Python, pythonrindex
The rindex () method returns the last index found for the Child str. You can select the string [beg: end] that restricts the search. If no such index exists, an exception is
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