22.07.2013 Views

A Comprehensive Introduction to Python Programming and ... - MSDL

A Comprehensive Introduction to Python Programming and ... - MSDL

A Comprehensive Introduction to Python Programming and ... - MSDL

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1.2 Language Features 5 / 75<br />

Notes:<br />

Sequence Description<br />

\newline Ignored<br />

\\ \<br />

\’ Single quote<br />

\" Double quote<br />

\a ASCII Bell Character (BEL)<br />

\b ASCII Backspace Character (BS)<br />

\f ASCII Form Feed Character (FF)<br />

\n ASCII Line Feed Character (LF)<br />

\Nname Unicode character named ’name’ (Unicode only)<br />

\r ASCII Carriage Return Character (CR)<br />

\t ASCII Horizontal Tab Character (TAB)<br />

\uhhhh Character with the 16-bit Hexadecimal value hhhh<br />

(Unicode Only)<br />

\Uhhhhhhhh Character with the 32-bit Hexadecimal value<br />

hhhhhhhh (Unicode Only)<br />

\v ASCII Vertical Tab Character (VT)<br />

\ooo ASCII Character with the octal value ooo<br />

\hh ASCII Character with the hexadecimal value hh<br />

1. Two string adjacent string literals will be concatenated at compile time. For<br />

example, "Hello"" world!" will be concatenated in<strong>to</strong> "Hello world!". This<br />

allows <strong>to</strong> easily break string literals across multiple lines. Comments are allowed<br />

between the parts of the string. Also, different quotation marks can be used for<br />

each part. The different parts of the string must be enclosed in parantheses if the<br />

string is <strong>to</strong> span multiple lines, if it is not already the case (eg for function calls).<br />

2. String literals can also be enclosed within three double quotes, in which case<br />

newlines within the string are become part of it.<br />

1.2.1.4 Imaginary Numbers<br />

<strong>Python</strong> provides built-in support for imaginary numbers. It defines 1j <strong>to</strong> be equal<br />

<strong>to</strong> √ −1. Imaginary numbers can be written in the form a + bj, where a <strong>and</strong> b are<br />

integers or floats.<br />

1.2.2 Variables<br />

Variables are not declared in <strong>Python</strong>. Since <strong>Python</strong> is a dnamically typed language,<br />

any variable can be assigned any value, regardless of its previous type. This also holds<br />

for instance variables in classes. Therefore, it is a good idea <strong>to</strong> initialize all instance<br />

variables in the construc<strong>to</strong>r <strong>to</strong> make sure that memory has been allocated for them, <strong>and</strong><br />

in order <strong>to</strong> make sure that they can safely be used inside the class. <strong>Python</strong> used <strong>to</strong> rely<br />

on a reference counting algorithm <strong>to</strong> free the unused variables. The newer versions of<br />

<strong>Python</strong> (ie 2.0 beta <strong>and</strong> above) rely on a more traditional garbage collection technique.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!