The processing code of a beginner Python array

Beginner python, the small edge of a few questions: There is a list A = [1, 2, 3, 4, 5, 6] Please use a according to 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 Print output, 2. Reverse a list to [6, 5, 4, 3, 2, 1] 3. Select the even number in a and the result is

A simple example of a Python program (communication)

Core code: The code is as follows: #!/usr/bin/python#Filename: friendbook.pyImport Cpickle as PImport SysImport timeImport OS ab={' xdex ': ' cneds@fnedf.com ',' laexly ': ' fev@fe.com ',' FUKC ': ' fexok@ver.com ',' Stifu ': ' stif@qq.com '} def

Python implements merge sort algorithm

Theory does not say much: The code is as follows: #!/usr/bin/pythonImport Sysdef merge (array, q, p, r):Left_array = array[q:p+1]Right_array = array[p+1:r+1]Left_array_num = Len (left_array)Right_array_num = Len (right_array)I, J, k= [0, 0,

Python code that can be used to monitor MySQL Master Slave status

The code is as follows: Import OSImport SysImport MySQLdbDEF getStatus (conn):query = "SHOW SLAVE STATUS"# Print Querycursor = Conn.cursor ()Cursor.execute (query)result = Cursor.fetchall ()return result[0]DEF resolve (conn):cursor = Conn.cursor ()

Summary of how Python handles a fixed number of characters at a time

First of all, to look at the case of a character each time, you can have the following methods to achieve: Method One: The code is as follows: >>> a= ' 1234567 '>>> List (a)[' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ']>>> Method Two: The code

Python program to download log files from a remote server

The code is as follows: Import OSImport SysImport FtplibImport socket ################################################################### Sign in the FTP server and download the log file.# Log in to production server download logs###################

Python shared reference (multiple variable references) sample code

The code is as follows: A = 3b = A First (Figure 1), you can see at a glance: Variable name and object, after running assignment statement B = A, the variable A, a, is pointing to the memory space of object 3.Assuming that a = ' python ' is

Description of the Python ID () function

>>> A = 2.5 >>> B = 2.5 >>> C = b >>> A is C False >>> A = 2 >>> B = 2 >>> C = b >>> A is C True When using the IS function to print a, B, respectively, is assigned a value of 2.5 and 2, found that:>>> A = 2>>> B = 2>>> ID (a)21132060>>> ID (b)2113

Code for assisted development using SQLAlchemy in flask

Installation method 1), Apt-ge installation The code is as follows: sudo apt-get install Flask-sqlalchemy 2), download the installation package for installation The code is as follows: # can be used directly in the PY after installationImport

Various sort algorithm codes implemented by Python

The code is as follows: #-*-Coding:utf-8-*-# Test various sorting algorithms# link:www.bitsCN.com# DATE:2013/2/2 #选择排序def select_sort (Sort_array):For I, Elem in Enumerate (Sort_array):For J, Elem in Enumerate (sort_array[i:]):If sort_array[i] >

Python regular expression fix for Web site article font not uniform resolution method

There are defined fonts in the large frame of the website, including font size and color, which may be copied from other websites when the user publishes the article, and the copying process retains the font description information. When the article

Python string Formatting code

Format Summary: Format description format description %% percent sign% (extra% is escape effect) /td> % c character and its ASCII code %s

Python Test Implementation method

1) doctest Using Doctest is a similar approach to command-line attempts, and the usage is simple, as follows The code is as follows: def f (n):""">>> F (1)1>>> F (2)2"""Print (n)if __name__ = = ' __main__ ':Import DoctestDoctest.testmod () It

Python generates an instance code of Chinese verification Code randomly

Python code The code is as follows: #-*-Coding:utf-8-*- Import Image,imagedraw,imagefont Import Random Import Math, string Class Randomchar (): "" for random generation of Chinese characters "" " @staticmethod Def Unicode (): val = Random.randint (0

Python string split usage share

For example, the format of our storage: Format of:Name, age | Another user name, age Name:haha,age:20|name:python,age:30|name:fef,age:55 Then we can cut the string object into a list by the split method of the string object. A = '

Python del () function usage

The sample program is as follows: >>> a = [-1, 3, ' AA ', 85] # define a list>>> A[-1, 3, ' AA ', 85]>>> del a[0] # delete No. 0 element>>> A[3, ' AA ', 85]>>> del A[2:4] # Removes the element starting from the 2nd element to the 4th. Including

Python Download the implementation code for a sister graph on a multi-play image

The code is as follows: #-*-Coding:utf-8-*-Import HttplibImport UrllibImport stringImport reDef getcontent (): #从网站中获取所有内容conn = Httplib. Httpconnection ("tu.duowan.com")Conn.request ("GET", "/m/meinv/index.html")R = Conn.getresponse ()Print

Python Backup files and scripting code for MySQL database

The code is as follows: #!/usr/local/pythonImport OSImport timeImport stringsource=['/var/www/html/xxx1/', '/var/www/html/xxx2/']Target_dir= '/backup/'Target=target_dir+time.strftime ('%y%m%d ')Zip_comm= ' zip-r%s '% (target, "". Join

Let Python's cookie.py module support the colon-key approach

For compatibility, you can only select compatible: Colon. Very simple, modify the Cookie.morsel The code is as follows: #!/usr/bin/python#-*-Coding:utf-8-*-"" "Morselhook, fix Cookie.CookieError:Illegal key value:ys-tab:entrance:e"""Import

Python Basics of manipulating MongoDB

First run the Easy_install Pymongo command to install the Pymongo driver. Then do the following: Create a connection The code is as follows: In [1]: Import PymongoIn [2]: Connection = Pymongo. Connection (' localhost ', 27017) Switch to database

Total Pages: 4013 1 .... 3639 3640 3641 3642 3643 .... 4013 Go to: GO

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.