Beginning Python Visualization: Crafting Visual Transformation Scripts

Page 85

C H A P T E R 3 N P Y T H O N F O R P R O G R A M M E R S

::: ] 9 -'.f ::: ]*na]h -*, ::: ]*ei]c .*, You can use most any operator on complex numbers just as you would on floating-point numbers. Once a computation involving a complex number is encountered, the remaining computation will remain a _kilhat, that is, integers and floating-point values are promoted to complex values. You can convert a number to a complex number using the _kilhat$na]hW( ei]cY% function. In case ei]c is provided, it holds the imaginary value of the complex number: ::: _kilhat$-,% $-,',f% ::: _kilhat$-,( .% $-,'.f% The _kilhat data type as well as examples on using it will be discussed in Chapter 7.

Strings Per the classic Python definition, strings are an immutable sequence of characters. This means a string is a sequence of characters, and it is unchangeable: you can’t change the characters. I know that this might seem odd at first: you’re probably thinking, “How do I work with strings if I can’t modify them?” The answer is that you create new strings based on your current string.

Expressing Strings There are several ways to express a string: single quotes, #opnejc#; double quotes, opnejc ; and triple-double-quotes, opnejc (phew), to name a few. And there are even more: raw strings denoted by the letter n such as n opnejc and Unicode strings denoted by the letter q, for example, q qje_k`a . To express a basic string, use single quotes as follows: ::: #olhep# #olhep# In case your string has a quote in it, you’ll have to escape it with a backslash (X): ::: #epX#o ] olhep# ep#o ] olhep The reason we escaped the quote that’s part of the word ep#o is so that the quote before the letter o won’t terminate the string. Single quotes and double quotes are interchangeable. Therefore, we could’ve achieved the same result, without escaping the quote that’s part of the word ep#o, by replacing the enclosing quote (the ones at the beginning and end) with double quotes: ::: ep#o ] olhep ep#o ] olhep

65


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.