diff --git a/python-3-vs-python-2/index.html b/python-3-vs-python-2/index.html index c8e7860..483c10c 100644 --- a/python-3-vs-python-2/index.html +++ b/python-3-vs-python-2/index.html @@ -1,124 +1,124 @@ - - - -
Python 2 released in 2000; legacy code, no longer supported after 2020.
-Python 3 introduced in 2008; the future of Python, ongoing support.
-Key differences in syntax, libraries, and error handling.
-Python 2: Print statement print "Hello, world"
Python 3: Print function print("Hello, world")
Python 2: Dividing two integers results in an integer. 3 / 2 = 1
Python 3: Division results in a float. 3 / 2 = 1.5
Use //
in Python 3 for integer division.
Python 2: Strings are ASCII by default.
-Python 3: Strings are Unicode by default.
-Better support for non-English languages and symbols in Python 3.
-Python 2: xrange()
, print
, except Exception, e:
Python 3: range()
, print()
, except Exception as e:
More intuitive and consistent syntax in Python 3.
-Python 2: Libraries may not be compatible with Python 3.
-Python 3: A large number of Python 2 libraries have been updated or replaced.
-Improved and more modern standard library in Python 3.
-Python 2: Less strict about mixing types (e.g., bytes/str).
-Python 3: Strict type checking, leading to fewer subtle bugs.
-Python 3 offers significant improvements and future-proofing.
-Migrating from Python 2 to 3 requires careful consideration but is encouraged for long-term projects.
-Use tools like 2to3
for code translation and testing.
Python.org documentation
-"Porting to Python 3" guide
-Online tutorials and forums
-Brief History of Python
+ Python 2 release in 2000
+ Python 3 release in 2008
+ Key differences aim to make Python more powerful and easier to use
Print function
+ Python 2: print "Hello, world!"
+ Python 3: print("Hello, world!")
+ Integer division
+ Python 2: 3/2 = 1
+ Python 3: 3/2 = 1.5
Python 2: Strings are ASCII by default. Unicode string with u"unicode"
+ Python 3: All strings are Unicode. Bytes type for ASCII text: b"ascii"
Changes in standard library
+ Python 2: urllib
, urllib2
, httplib
+ Python 3: Unified under urllib
package
+ Range function
+ Python 2: xrange()
for efficient looping
+ Python 3: range()
is now like xrange()
Syntax for exception handling
+ Python 2: except IOError, e:
+ Python 3: except IOError as e:
Enhancements in iteration
+ Python 3 introduces new behavior for dict methods .keys()
, .items()
, and .values()
which return views instead of lists
Python 2 end of life in 2020
+ No more official support or updates
+ Encouragement to migrate to Python 3 for security and latest features
Tools like 2to3
can help in converting Python 2 code to Python 3
+ Considerations for maintaining compatibility
+ Importance of testing during migration
Python 3 offers significant improvements and is the future of Python
+ Transitioning to Python 3 is essential for access to new features and continued support
Official Python documentation
+