There are various string operation functions in Python. In history, the string class experienced a cycle in Python. At the very beginning, Python had a special string module. To use the string method, we had to import it first. However, due to the
[Python] sorting strings in one row
This article was originally published in love butterfly blog (http://blog.csdn.net/lanphaday), welcome to reprint, but please keep this statement.
In general, sorting a string in python is quite troublesome:1.
Interpretation http://lists.fedoraproject.org/pipermail/users/2009-August/087219.html from foreigners
It seems I have two python2.6 folders located in/usr/lib
/Usr/lib64 respectively. Most Python stuff (source) is in/Usr/lib64/python2.6 but when
Random INTEGER:
>>> Import random
>>> Random. randint (0, 99)
21
Randomly select an even number between 0 and 100:>>> Import random>>> Random. randrange (0,101, 2)42
Random Floating Point Number:>>> Import random>>> Random. Random ()0.8541537
In fact, the dictionary cannot be sorted. We arrange items, that is, dict. Items (), which converts the dictionary into a list.
The prototype of the sorted function is:
Sorted (iterable [, CMP [, key [, reverse])
Iterable: The iterable type;
CMP:
Function Definition
Def Hello (name, age = 10, Gender = 'F '):
Print 'user info :'
Print 'name is % s' % name
Print 'Age is % d' % age
Print 'gender is % C' % gender
There are several Calling Methods
Hello ('Jim ')
Hello ('Jim ', 11)
Sub (repl, string [, Count]) | re. sub (pattern, REPL, string [, Count]):Use repl to replace each matched substring in the string, and then return the replaced string.When repl is a string, you can use \ ID, \ G , \ G to reference the group, but
From: http://our2848884.blog.163.com/blog/static/146854834201192393137281/
Anyone who has learned Python should know that python contains single quotation marks, double quotation marks, and three quotation marks. But what are their differences?
The easy_install tool in python is very good, and its function is similar to pear in PHP, GEM in ruby, or CPAN in Perl.If you want to use the easy_install tool, you may need to install setuptools first, but the cool way is to use the ez_setup.py
Python has two built-in functions,Locals ()AndGlobals ()They provide dictionary-based access to local and global variables.
First, it is a glossary about namespace. It is boring, but it is very important, so be patient. Python uses something called
PythonThe module method in the subdirectory is relatively simple. The key is to find the module path in SYS. Path.File.The following describes several common cases:(1) The main program and Module Program are in the same directory:As shown in the
The simplest is to use Python's urllib2.urlopen () function;Then, there is a website that likes to seal people, so you have to find a batch of agents to capture their information in turn;Some websites do not allow programs to crawl, so some header
Download a lot of compressed files and write a script
The WinRAR command is used in Python, so generally compressed files are supported.
Some compressed files have no corresponding libraries in Python.
You must add WinRAR to the path environment
Thanks for a script for automatically downloading the blog of the specified person.
This script is used to download the csdn blog
In the same way, you can download blogs from other websites, such as Sina.
Sometimes page access is denied. Just run
More articles on the Internet use Django, webpy, and other frameworks. Because I only use its CGI instead of pure web development, I do not plan to use such frameworks for the moment, directly use the flup package (in fact, most of the frameworks
With is available in Python 2.5 and needs from _ future _ import with_statement. It has become the default keyword since Python 2.6.That is to say, with is a control flow statement, which is similar to if/For/while/try. With can be used to simplify
Example of writing multiple threads
The threading module of Python contains the following: Due to the global interpreter lock, in cpython only one thread can execute Python code at once (even though certain performance-oriented libraries might
This document introduces the basic Python profilter method and uses openstack Nova as an example to show how to use it. The profiler method described in this article is different from the commonly used Python method.
CprofileModule,
CprofileThe
1. Convert class or object to dict,
The attributes of a class object are different from those of a class object. If you are interested, you can view the _ dict _ of the output class and object,
>>> class A(object):... def __init__(self):...
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