---
jupyter:
  anaconda-cloud: {}
  jupytext:
    text_representation:
      extension: .Rmd
      format_name: rmarkdown
      format_version: '1.0'
      jupytext_version: 0.8.1
  kernelspec:
    display_name: Python 3
    language: python
    name: python3
  language_info:
    codemirror_mode:
      name: ipython
      version: 3
    file_extension: .py
    mimetype: text/x-python
    name: python
    nbconvert_exporter: python
    pygments_lexer: ipython3
    version: 3.5.2
---

# Strings

Much of the world's data is text, and a piece of text represented in a
computer is called a *string*. A string can represent a word, a sentence, or
even the contents of every book in a library. Since text can include numbers
(like this: 5) or truth values (True), a string can also describe those
things.

The meaning of an expression depends both upon its structure and the types of
values that are being combined. So, for instance, adding two strings together
produces another string. This expression is still an addition expression, but
it is combining a different type of value.

```{python}
"data" + "science"
```

Addition is completely literal; it combines these two strings together without
regard for their contents. It doesn't add a space because these are different
words; that's up to the programmer (you) to specify.

```{python}
"data" + " " + "science"
```

Single and double quotes can both be used to create strings: `'hi'` and `"hi"`
are identical expressions. Double quotes are often preferred because they
allow you to include apostrophes inside of strings.

```{python}
"This won't work with a single-quoted string!"
```

Why not? Try it out.


The `str` function returns a string representation of any value. Using this
function, strings can be constructed that have embedded values.

```{python}
"That's " + str(1 + 1) + ' ' + str(True)
```

{ucb-page}`Strings`
