Just getting started with Python and implementing a helloworldProgram--- About the UDP socket communication demo.
First, the implementation on the server side is as follows:
Import socket, tracebackhost = ''# bind to all interfaces Port = 5150
Common Python types
>>> A = 1 >>> type (a) >>>> A = 1.0 >>> type () >>> A = 'abc' >>> type (a) >>> A = (1, 2) >>> type (a) >> A = [1, 2]; >>> type () >>> A = {1, 2 }>>> type (a) >>> A = {1:1, 2: 2 >>>> type (a)
List, set, and dict are variable
Concise Python tutorial --- 14. Python standard library
The Python standard library is installed with Python and does not need to be installed independently. The Python standard library contains a large number of very practical modules that
Log usage:
1. The standard logging module can basically meet my work requirements.
2. Set log initialization:
Logging. basicconfig (
Filename ="Test. log",
Format ="[% (Asctime) S-% (levelname) S] % (Message) s [% (filename) s, % (lineno) D]
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
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)
Let's take a look at the following:
Code The "weird" phenomenon. In Windows, I Have A f.txt file, which contains the following content. Helloworld code 1,
With open('f.txt ', 'R') as F: Print F. readlines () with open('f.txt', 'rb') as F: Print F.
The atexit module is simple. Only one register function is defined for registration.ProgramWhen you exit the callback function, we can perform some resource cleanup operations in this callback function.
Note: If the program is abnormal crash or
Automatic Mail sending should be a common requirement. Python provides corresponding module support. Let's look at the code for automatic mail sending:
# Coding = UTF-8
Import smtplib
From email. Mime. Text import mimetext
From email. Mime.
I have never systematically studied data structures and algorithms from the beginning.
Partial reference: http://interactivepython.org/courselib/static/pythonds/SortSearch/sorting.html
#-*-Coding: cp936-*-# insert sort def insertsort (a): for I in
Document directory
Built-in function: BIFS
User Function: UDF
Built-in method: BIMs (only the corresponding bit has the corresponding BIM)
User method: UDM
Reference: First Half of chapter 14 of Python core programming
Built-in function
Use threading to inherit the treading Method
# Coding: utf8''' def isprime (m): # prime number refers to the number that can only be divisible by 1 and itself for I in range (2, M/2 + 1 ): if M % I = 0: Return false return trueif _ name _ = '_ main
When it reaches the fifth level, there is no other things. The English meaning is "Pronunciation", and it is still confused here.
What are you doing? Check the source code. The source code of the page is as follows:
peak hell pronounce it
The
Concise Python tutorial --- 12. Input and Output
File
You can create a file class object to open the file. Use the Read and Write methods of the file class to read and write files.
For example, open the file "C:/abc.txt" (if this file must be
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
XML usage:
1. xml. etree. elementtree is a useful module for processing XML message packets.
2. The element executes the XML root node.
3. ELEM. Find (PATH): Find the child node whose path is path under the root node.
4. ELEM. findall (PATH): The
Developing multi-threaded application systems is a common requirement in daily software development. The current programming language provides good support for multi-threaded development, whether through library support or built-in multi-threaded
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
Asynchronous callback is required in many scenarios to avoid blocking. This is a simple example.
#! /Usr/bin/ENV Python #-*-coding: UTF-8-*-import loggingimport queueimport threadingdef func_a (A, B): return a + bdef func_ B (): passdef func_c (a,
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