Strings [Oct. 18, 2012, 9:05 p.m.]
We will commonly be working with text data, or 'strings' in Python (and other languages). Strings are expressed using single ( ' ) or double ( " ) quotes.
>>> 'This is a string of characters' # Single quotes 'This is a string of characters' >>> "This is also a string of characters" # Double quotes "This is also a string of characters"
Strings can be referred to by variables, for later usage.
>>> a_string = "I really enjoy working with strings." >>>
Notice that when we assign the memory location of the string to a variable called 'a_string' the interpreter simply displays a new prompt. This differs from when we typed a string directly at the prompt, without a variable assignment.
We can easily retrieve the string by referencing the 'a_string' variable.
>>> a_string 'I really enjoy working with strings.'
Note that the variable 'a_string' does not actually contain the string. Rather, the string is stored in the computer's memory, and the variable stores the memory address where the string is stored.