Skip to ContentGo to accessibility pageKeyboard shortcuts menu
OpenStax Logo

Highlights from this chapter include:

  • A string is a sequence of values that represents Unicode code points.
  • An index refers to the position of a value in a sequence (string, list, tuple).
  • Positive indexes range from 0 to length–1. Negative indexes range from –1 to –length.
  • F-strings are a convenient way to print multiple outputs and format integers and floats.
  • Variables refer to objects. Memory diagrams are useful for drawing variables and objects.
  • A list object can be used to refer to multiple objects, by index, using the same variable.
  • A tuple is similar to a list, but uses parentheses and cannot be changed once created.
Code Description
ord(c)
Gets an integer representing the Unicode code point of a character.
chr(i)
Converts a Unicode code point (integer) into a One-character string.
'\n'
Escape sequence for the newline character.
'\t'
Escape sequence for the tab character.
f"{number:.02d}"
Creates a string by formatting an integer to be at least two digits.
f"{number:.2f}"
Creates a string by formatting a float to have two decimal places.
id(object)
Gets the identity (memory location) of an object.
type(object)
Gets the type (class name) of an object.
my_list = ["a", "b", "c"]
Creates a list of three strings.
my_tuple = ("a", "b", "c")
Creates a tuple of three strings.
my_list[0]

Gets the first element ("a") of my_tuple.

my_tuple[-1]

Gets the last element ("c") of my_tuple.

Table 3.5 Chapter 3 reference.
Citation/Attribution

This book may not be used in the training of large language models or otherwise be ingested into large language models or generative AI offerings without OpenStax's permission.

Want to cite, share, or modify this book? This book uses the Creative Commons Attribution License and you must attribute OpenStax.

Attribution information
  • If you are redistributing all or part of this book in a print format, then you must include on every physical page the following attribution:
    Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction
  • If you are redistributing all or part of this book in a digital format, then you must include on every digital page view the following attribution:
    Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction
Citation information

© Mar 15, 2024 OpenStax. Textbook content produced by OpenStax is licensed under a Creative Commons Attribution License . The OpenStax name, OpenStax logo, OpenStax book covers, OpenStax CNX name, and OpenStax CNX logo are not subject to the Creative Commons license and may not be reproduced without the prior and express written consent of Rice University.

This book utilizes the OpenStax Python Code Runner. The code runner is developed by Wiley and is All Rights Reserved.