Python Programming Overview 3
Python Programming Overview 3
(1) Source File Encoding
UTF-8
- Stands for 8-bit Unicode Transitional Format
- Capable of encoding all possible characters in Unicode
- The dominant character encoding for the Web (81.4% of all web pages as of 11/2014)
- Backward-compatible with ASCII
Encoding Source
- Most common way is to define a special comment to define the encoding:
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- Dependent on the editor you use
The Main Point
- You typically don’t need to worry about this
- In Python 3, everything is encoded in UTF-8 by default
- In Python 2.7, ASCII encoding is the default
- You can still specify Unicode string literals with the “u”” delimiter (ex: u’ a Unicode string’)
Vim example
(2) Comments
Two Types of Comments
- In PEP8, two types of comments are defined
- Block comments
- Inline comments
- Both are prefaced with a # character
Block Comments
- Used to document the code that follows them
- Ident to the same level as the code being documented if necessary
- Paragraphs are separated with a newline that also has a # symbol
Inline Comments
- Used on the same line as a statement
- Often unnecessary, but if they are necessary, use them sparingly
- Possibly distracting if they only state the obvious

0 Comments