This article mainly introduces several examples of code that is compatible with Python and Python 3.x, in Python2.7.x, because some Python 3 code writing features are used, it is possible to write compatibility code in some original differences. For more information, see
Wri
... One of the most important advantages of Python 2 is that it has a large number of third-party libraries that can be used to do anything, but Python 3 doesn't have that advantage. Admittedly, there are a lot of libraries that have been ported to Python 3, but there are mo
Python learning notes (10) Python collection (3) and python learning notes
Set operation
Relationship between elements and sets
The relationship between elements and a set is to determine whether an element is a member of a set. "A" in aset
1 >>> s = set ([1, 2, 3, 4]) 2 >>>
Reply content:Let me correct and comment.
> 1. Print is no longer a statement, but a function, such as the original print ' ABC ' is now print (' abc ')
However, python2.6+ can use the from __future__ import print_function to achieve the same functionality
> 2. In Python 3, there is no old-fashioned class, only the new class, which means no more like this class Foobar (object): Pass explicitly sub-class obj
This article lists the differences between Python 2 and Python 3. This is an incomplete list and will be replenished gradually in the future.
1. Print output
Suppose you want to output "HI", let's look at Python 2 and Python 3 in
same linePython can use multiple statements in the same row, with semicolons (;) split between statements, and here's a simple example:Import ' Runoob ' ' \tabc\n ')Print outputThe print default output is newline, and if you want to implement no wrap, you need to add a comma to the end of the variable:Multiple statements form a code groupIndenting the same set of statements constitutes a block of code, which we call the code group.Compound statements such as if, while, Def, and class, the first
Round () There are some differences between py2 and Py3With the default precision, the data type of the round return value changes :Py2>>> Round (2.6)3.0>>> >>> type (round (2.6))'float 'Py3>>> Round (2.6)3>>> >>> type (round (2.6))class' int 'This rounding problem seems to be still there.>>> round (2.3555, 3)2.356>>> >>> round (2.355, 2)Meet a change record one.[Python
"shell."4.5 dictionary built-in functions methods
Condition control
5.1 Article Control FlowA python conditional statement determines the code block that executes by executing the result of one or more statements (true or false). You can easily understand the execution of conditional statements by:5.2 If statementThe general form of the IF statement in Python is as follows:If "condition_1" i
3-1.Identifier. Why is variable name and variable type declaration not required in Python?[Answer] These answers are found online.In Python, the object type and memory are determined at runtime. When a value is created, the interpreter determines the type of the new object based on the syntax and the right operand.The variable is automatically declared when it is
Conversion of Python 2.7 to Python 3.X under UbuntuSince Ubuntu itself comes with Python 2.7, and Python 3.X is a lot different from 2.7, there are many inconveniences when using Python
, and uses the third kind of object (rule system) to decide the chess game.It is obvious that object-oriented is a function to divide a problem, not a step. The same is the game, the behavior in the process-oriented design scattered in the total number of steps, there is likely to be different drawing version, because the designers often consider the actual situation of a variety of simplification. In object-oriented design, the drawing can only appear in the Checkerboard object, thus guaranteei
This article compares the execution efficiencies of the Python 2 and Python 3 pairs of collection-list
First I define a for_test function, and then use the Magic function of Ipython to perform the test of execution speed%timeit
%timeit automatically executes the objective function more than once to obtain a more accurate result.
in the process of testing, we
Python function Programming Guide (3): iterator details, python programming guide
3. iterator
3.1. Iterator Overview
An iterator is a way to access elements in a set. The iterator object is accessed from the first element of the set until all elements are accessed.
The iterator cannot be rolled back and can only be ite
2015/11/3 use Python to write a game. Getting started with pygame (3): font module, event display, and error handling, pythonpygame
In the game, text is usually displayed, and even the Russian square should show scores. So how should we display the text? Today, let's take a look at the font module of pygame.
Use font Module
Pygame can directly call the system f
Visual studio 2015: Build a python development environment, and get started with [3], 2015 python
In the previous blog, I set up a python development environment in Windows. I was a beginner in python. Many school friends mentioned that they wanted to use visual studio 2013/
Many beginners in Python will ask: Which version of Python should I learn? For this question, my answer is usually "first choose the Python tutorial that best suits you, which version of Python you use in the tutorial, and you use that version." Study the difference between the different versions. "But if you want to d
1. Python User interactionThe program will inevitably interact with the user.For example, you would want to get the user's input and print out some returned results to the user. We can implement this requirement by using the input () function and the print function, respectively.1 #! /user/bin/env Ptyhon2 #-*-coding:utf-8-*-3 #Author:visonwong4 5Name = input ("Name:")6age = Int (input ("Age :"))7Job = input
. The slice from I to J consists of all characters marked between I and j edge.
For non-negative indexes, the slice length is the index difference if they are within the boundary. For example, the length of word [1: 3] is 2.
The built-in function Len () returns the string length:
3.1.3 about Unicode
From python3.0, all strings support Unicode.
The advantage of Unicode is that it provides an ordinal number for each text character in each current script
are saved with 2 bytes, the characters in East Asia are saved in 3 bytes ...stored in this extensible way.OK above understand:1, what ASCII encoding2, what Unicode encoding3, what UTF-8 codeReview the occurrence of garbled characters cause: 1, no character set 2, character set conflictsLook back and see why you need to add the specified code to the second line? In the 2.x version of Python Pyton when expla
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.