6. Object-oriented 6.1 classes and instancesClass Student (object):#注意: There are two underscores before and after the special method "Init"!!!def __init__ (self,name,score): #第一个参数self永远是类创建的实例本身Self.__name=nameSelf.__score=scoredef print_score
in Python, there are four types of basic operations for a file:1. Open Filefile_obj = open ("File path", "mode")the commonly used open file modes are:r: Open the file as read-only. The pointer to the file will be placed at the beginning of the file.
1,python (build-in) package ( imported primarily with import) and external (external) package1.1 Comes with package example: OS pack; OS.GETWD ()2. Using Easy_install and pip to install extension files2.1 For example Pip install request (s)3.python
The Python language does not resemble Java, JavaScript, and other languages:What are the terms of the sentence? Result of the condition being true: the result when the condition is falseSuch a three-mesh operation, but Python also has its own
Existing two files, one file name is ideal.py, the other is hub.py, both are in the directory Modualsio.The specific contents of ideal are:num = 3Class Foo (object):Global numdef foo (self):Return num*3PS: In this usage, if we do not use global to
In a regular expression, group () is used to present a string that is intercepted by a packet , () to groupImport rea = "123abc456" Print Re.search ("([0-9]*) ([a-z]*] ([0-9]*)", a). Group (0) #123abc456, return to overall print re.search (" ([0-9]
1, the definition of the module:Module definition: Used to logically organize Python code (variables, functions, classes, logic; The purpose is to implement a function), which is essentially a Python file at the end of the. Py.Add:Package definition:
Python functionsFirst look at the following code:def welcome_info (): " Show welcome message " Print ("Hello world! " ) return 0As in the code, a function is defined.The result after the call is:Welcome_info () # call function Hello
8 errors, debugging and testing 8.1 error handlingAll exceptions are from baseexceptionError logged:# err_logging.pyImport loggingdef foo (s):return 10/int (s)def bar (s):return foo (s) * 2def main ():TryBar (' 0 ')Except Exception as
Python SYS ModuleThe SYS module provides a number of functions and variables to handle different parts of the Python runtime environment.Handling command-line argumentsSYS.ARGV #现从程序外部向程序传递参数 [*],0 represents the program itself#!/usr/bin/env python#-
9 IO ProgrammingIn Python, file reads and writes are done through file objects opened by the open () function. Using the WITH statement to manipulate file IO is a good habit.Read the fileTryf = open ('/path/to/file ', ' R ')Print (F.read
A computer is a machine that can do mathematical calculations as the name implies, so a computer program can handle a variety of values. However, the computer can handle far more than the numerical value, but also can deal with text, graphics, audio,
1. Bubble sort#[6,3,9,4,2]defBubble_sort (LI): n=Len (LI)#determine the number of times the bubble is sorted n-1 forJinchRange (n-1):#0 1 2 3Count=0#Bubble sort a trip, put the largest one number to the right forIinchRange (N-1-J):#0 3
Reference blog:1,http://www.cnblogs.com/luchen927/archive/2012/02/27/2367108.html2,http://www.cnblogs.com/ucos/p/5871354.htmlIdeas: Find the smallest one from all the sequences and put it in the first position. Then look at the smallest of the
The installation of python3.5 and 2.7 coexist in Centos 7, and centospython3.5
Centos 7 is installed with python 2.7 By default. You need to install python 3.5
1. Install Dependencies
1 yum install openssl-devel bzip2-devel expat-devel gdbm-devel
Socket communication,
Note that socket communication is blocked by default. The recv and accept functions are blocked.
1. When the client Exits normally, the con channel on the server will be closed normally, and the recv value is blank.
2. in
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