This article mainly introduces the comparison between Python 2 and Python 3 and encoding. This article describes in detail. For more information, see the following. I. version comparison
The Python version is mainly divided into two categories:
Python 2.7.3 is the most wide
Sixth day of Python learningWrite this blog to motivate yourself and share your experiences and issues with others.First, class notes1. the method that can be invoked must be an object. 2. Basic process of file operation: open--operation--close (focus on operation)3. The mode of opening the file is: (three most basic mode of operation)
R, read-only mode (default).
W, write-only m
See this topic you may guess what I want to say next, oh, yes, that is the list of these two different versions of the But not!
You'll find that Python has two major versions, Python2 and Python3, but Python is different from other languages, backward-compatible, and Python3 is backward-compatible, but most of the components and extensions are based on Python2, Here's a summary of the difference between Py
Python learning 3: List, tuples, and python learning list1. List: 1. How to define a list:
list1 = [1,2,3,4,"hello","world"]
As shown above, list1 is a list. The content of the list is enclosed in brackets.
print(list1[2])
The value is calculated using the following table. The following table starts from 0, returns the subscript numbered 2, and the obtained value
40. Function Description:Document descriptionProcedure is a function with no return valueProcedures also have return values in Python: (Explicit)41. Function Introduction 2To realize the exhausting log functionReference the above time formatReturn is the terminating statement:Put it into a tuple and return it to you.Return the TEST2 function memory address:What's returned:Why do you want to return a value? Because I want the result of the entire execu
default folder"% Len (Filearray))GE = len (filearray)Matrix = [None] * GE# implement read and write data# The following is the reading of all the files into the three-dimensional list cell[][][] (not including the table header)Import xlrdFor IInchRange (GE):fname = Filearray[i]BK = Xlrd.open_workbook (fname) TrySH = bk.sheet_by_name ("Sheet") Except Print"Sheet not found in file%s, read file data failed"% fname)nrows = Sh.nrowsMatrix[i] = [0] * (nrows-1)Ncols = Sh.ncols For MInchRange (Nrows-1)
Import OSDefRemove ():Filearray = []Address_excel=E\\Totally\\Financepdf "F_list = Os.listdir (address_excel) For FileNAMEIn F_list: # Os.path.splitext (): Detach file name and extension if os.path.splitext (FileNAME) [ 1] = = Filearray.append (FileNAME) # above is to read all the Excel tables from the Pythonscripts folder and store all the names in the list Filearray print ( "There are%d documents in the default folder"% Len (filearray)) GE = len (filearray) for I Span style= "COLOR: #c
Assume is s a string of lower case characters.Write A program This prints the longest substring of in s which the letters occur in alphabetical order. For example, if s = ‘azcbobobegghakl‘ , then your program should printLongest substring in alphabetical order Is:begghIn the case of ties, print the first substring. For example, if s = ‘abcbcd‘ , then your program should printLongest substring in alphabetical order IS:ABC# Paste Your code into this boxCount = 1result = S[0]While S:Newcount = 1New
Python Reading Notes-Chapter 3, chapter 4, python Reading NotesChapter 3 1. string formatting >>> format = "hello % s world" >>> values = ('World', 'hot ') >>> print format % values # You can also receive a single string or use the % f % d type. When matching multiple parameters with c's printf, you should use parenthe
Python learning path 3: python learning pathContent of this section:
Common string processing.
Format the output string.
String replacement.
Conversion of strings and binary data.
Dictionary operations
String operation
Common string processing
Name = 'vector 'print (name. capitalize () # print (name. count ('E') # determine the number of print (name. cente
Python-crawler Problem Solving Thinking (3), python Crawler
Continue with the content of the previous article. In the previous article, the crawler scheduler has been written, and the scheduler is the "brain" of the whole crawler program. It can also be called a command center. Now, we need to write the other components used in the scheduler. First, it is the u
QQ space Python crawler (3) --- final chapter, python Crawler
After testing, the code in the previous section is successfully run, and the next step is to add loop crawling to get all the instructions -. -
Complete code:
1 import requests 2 import json 3 import OS 4 import shutil 5 import time 6 7 qq = 627911861
The following problems involve the makeTextFile. py and readTextFile. py scripts.[Note] the source code of makeTextFile. py and readTextFile. py found on the network is slightly different from the original book example.
'Maketextfile. py -- create text file'
Import OS
# Get filenameWhile True:Fname = raw_input ('enter file name :')If OS. path. exists (fname ):Print "*** ERROR: '% s' already exists" % fnameElse:Break
# Get file content (text) linesAll = []Print "\ nEnter lines ('.' by itself to q
Python (data structure and algorithm [3]) and python (advanced tutorial)Maps keys to multiple values in the dictionary.
One-click multi-value dictionary
d = {'a':[1,2,3], 'b':[4,5]}e = {'a':{1,2,3}, 'b':{4,5}}
Availablefrom collections import defaultdictThe default dictionary class is used. One feature of the default dictionary class is to automatically initializ
is, if all references do not exist, the system will destroy this object.2. Variable names and objects:Python stores data based on objects. The relationship between variable names and objects is different from that between C/C ++ variable names and memory addresses. In Python, the variable name cannot change the object value. Instead, the variable name points to the new object. In C/C ++, if the variable name is assigned a value again, the correspondi
Basic Python tutorial 2-3: print a sentence in the "box" with the correct width. Basic python tutorial
Sample Code:# Obtain the sentence lengthSentence = input ('plese input a sentence: ') # He's very naughty boyScreen_width = 100# Getting the length of TextText_width = len (sentence)# Text widthBox_width = text_width + 10# Calculate the number of free formats on
1.the use of ' with open ... '2.the use of pickle (dump and load)For STEP1:The ' with open ... ' is the short format of ' try...except...finally 'For STEP2:You can store a list with pickle.dump () and get the content again with Pickle.load ()1>>>ImportPickle2>>> with open ('Test.pickle','WB') as data:3Pickle.dump (['a','2','et'],data)4 5 6>>> with open ('Test.pickle','RB') as ReadFile:7The_list =pickle.load (readFile)8 9 Ten>>>the_list One['a','2','et'] A>>>When use this method, you shou
to climb 58 of the same city as an example is to crawl the second-hand market all categories of links, that is, I said the large category of links;Find common features of these links, output them with functions, and store them as multiple lines of text. second, to obtain the details of the page we need the link and detailed information
page_parsing.py 1, to talk about our database:
First look at the code:
#引入库文件 from
bs4 import beautifulsoup Import
requests import
Pymongo #
Python 2.7 has an end-of-support time of 2020 and is now 2015 years old, but there are still a lot of packages in Debian that are based on Python 2 implementations. Debian maintainers are beginning to discuss the elimination of Python 2 seriously. Developer Paul Tagliamonte plans to transplant the Python 2 project to
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.