1. Computing

Transitioning from 2.x to 3.0

From , former About.com Guide

6 of 6

When Text is not Data

With this new support comes a very important distinction. Python 3.0 handles strings differently depending on whether the string is encoded. Unencoded strings are viewed as text and are handled as type str. Encoded strings, however, are binary data and are handled as type bytes.

The new Unicode default is underscored by the discontinuance of the u"..." literal for Unicode text. Instead, one must now use b"..." literals. The latter indicates overtly that the string in question is to be treated as encoded data.

 >>> y = b"Hello World!" 
 >>> type(y) 
 <class 'bytes'> 
 >>> y = "Hello World!" 
 >>> type(y) 
 <class 'str'> 
For more on managing the text and data differentiation in Python 3.0, see "A Guide to Text vs Data in Python 3.0".

  1. About.com
  2. Computing
  3. Python
  4. Python 3.0
  5. Learn Python 3.0 - Python 3.0 Tutorials - Python 3.0 Transition Guide - When Text is Data

©2013 About.com. All rights reserved.