Introduction To Python For Humanists William J B Mattingly download
Introduction To Python For Humanists William J B Mattingly download
Mattingly download
https://ebookbell.com/product/introduction-to-python-for-
humanists-william-j-b-mattingly-50506048
https://ebookbell.com/product/introduction-to-python-for-engineers-
and-scientists-open-source-solutions-for-numerical-computation-1st-
edition-sandeep-nagar-51197000
Introduction To Python For Kids Learn Python The Fun Way By Completing
Activities And Solving Puzzles 1st Ed Aarthi Elumalai
https://ebookbell.com/product/introduction-to-python-for-kids-learn-
python-the-fun-way-by-completing-activities-and-solving-puzzles-1st-
ed-aarthi-elumalai-32588532
https://ebookbell.com/product/introduction-to-python-for-engineers-
and-scientists-open-source-solutions-for-numerical-computation-
sandeep-nagar-6804432
https://ebookbell.com/product/introduction-to-python-for-science-and-
engineering-david-j-pine-7395824
Introduction To Python For Science And Engineering Second Edition
David J Pine
https://ebookbell.com/product/introduction-to-python-for-science-and-
engineering-second-edition-david-j-pine-58931256
https://ebookbell.com/product/introduction-to-python-for-econometrics-
statistics-and-data-analysis-5th-edition-kevin-sheppard-53726340
https://ebookbell.com/product/introduction-to-python-for-econometrics-
statistics-and-data-analysis-kevin-sheppard-11985190
https://ebookbell.com/product/introduction-to-python-for-science-and-
engineering-david-j-pine-231847460
https://ebookbell.com/product/computing-with-python-an-introduction-
to-python-for-science-and-engineering-feuhrer-22059306
Introduction to Python
for Humanists
This book will introduce digital humanists at all levels of education to Python. It provides
background and guidance on learning the Python computer programming language, and
as it presumes no knowledge on the part of the reader about computers or coding concepts
allows the reader to gradually learn the more complex tasks that are currently popular in
the field of digital humanities. This book will be aimed at undergraduates, graduates, and
faculty who are interested in learning how to use Python as a tool within their workflow.
An Introduction to Python for Digital Humanists will act as a primer for students who wish
to use Python, allowing them to engage with more advanced textbooks. This book fills a
real need, as it is first Python introduction to be aimed squarely at humanities students,
as other books currently available do not approach Python from a humanities perspective.
It will be designed so that those experienced in Python can teach from it, in addition to
allowing those who are interested in being self-taught can use it for that purpose.
Key Features:
• Data analysis
• Data science
• Computational humanities
• Digital humanities
• Python
• Natural language processing
• Social network analysis
• App development
Chapman & Hall/CRC
The Python Series
Python Packages
Tomas Beuzen and Tiffany-Anne Timbers
Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot
assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have
attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright hold-
ers if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged
please write and let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or
utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including pho-
tocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission
from the publishers.
For permission to photocopy or use material electronically from this work, access www.copyright.com or contact the
Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. For works that are not
available on CCC please contact mpkbookspermissions@tandf.co.uk
Trademark notice: Product or corporate names may be trademarks or registered trademarks and are used only for iden-
tification and explanation without intent to infringe.
DOI: 10.1201/9781003342175
Preface xv
Acknowledgments xix
v
vi Contents
V Conclusion 327
20 Conclusion 329
Index 331
Preface
I designed this textbook to serve two functions. First, it will function as a primer to Python
for humanists (or, more generally, those without coding experience or a background in
computer science). In this regard, readers will acquire a basic understanding of necessary
background information, such as data and data structures, as well as the basics of Python.
Second, this textbook is designed to not only provide the reader with a basic under-
standing of Python and how to use it, but how to apply it specifically to humanities-based
problems. The book particularly explores applying Python in data analysis with Pandas,
natural language processing (NLP) with spaCy, topic modeling with Gensim (for LDA topic
modeling) and Top2Vec (for modern topic modeling), and social network analysis with
NetworkX, Matplotlib, and PyVis. It also teaches readers how to design quick applications
with Streamlit and deploy them in the cloud with Streamlit Share.
All code throughout this textbook is designed to be as reproducible as possible. The goal
is for the reader to only need to replace the default data with their own data (or with minimal
effort get their data into a structured format) and have similar results. This should allow the
reader to begin applying the methods discussed throughout this textbook with relative ease
to their own areas of expertise.
Part I of the textbook introduces the reader to the basics of Python. Here, we will
learn about the basics of coding (Chapter 1) and the essentials about data and data
structures and how to work with them via Python (Chapter 2). These chapters will
provide the necessary foundation for exploring key programming basics, such as loops
and conditionals (Chapter 3), functions, classes, and libraries (Chapter 4), and working
with external data, such as text files and JSON (Chapter 5). The final chapter of Part I
will introduce the reader to the basics of web scraping and working with data found on
the web.
After Part I, the reader will have a basic understanding of Python, its syntax, and be able
to begin working with data to design projects. The remainder of the textbook is designed to
reinforce all of the skills acquired in Part I. Each of the following parts of the textbook will
also introduce the reader to the key libraries associated with their respective subjects.
In Part II, we will take a deep dive into data analysis. In Python, the essential library for
working with data, specifically tabular data, is Pandas. We will learn the basics of Pandas
while working with the open-source Titanic dataset. By the end of Part II, the reader will
have an understanding of Pandas and be able to leverage it in their own projects.
Part III shifts focus to text analysis. Here, we will learn about natural language process-
ing (NLP) and how to use Python and the library spaCy to engage in NLP. This part of
the textbook presumes no knowledge on the part of the reader about NLP or linguistics.
It will, therefore, provide all the basic information needed to begin working with texts in
more robust ways. The reader will learn about two different approaches to NLP, specifically
rules-based (heuristics) and machine learning-based. Both serve different functions and
should be used in different situations. By the end of this part, the reader will have a basic
understanding of each and know when to use them. While the machine learning-based
approaches will be rooted in using off-the-shelf spaCy models, the reader will learn how
to use NLP rules to create custom solutions. The final chapter of this part of the textbook
xv
xvi Preface
will look at a real-world problem, creating a rules-based heuristic pipeline to identify and
extract specific types of entities from texts.
Part IV shifts to other applications of Python to humanities-based problems. In Chap-
ter 14, we will learn how to do topic modeling, specifically Latent Dierlicht Allocation (LDA)
topic modeling so that they will have an understanding of the basic concepts and the history
of the field. After this, we will learn about more recent approaches to topic modeling using
machine learning with the library Top2Vec. Chapter 15 will look at performing text analysis
on larger documents with BookNLP. In Chapter 16, we will look at Social Network Analysis
with NetworkX and Matplotlib to produce static maps. We will also learn how to create
dynamic JavaScript and HTML network maps with the Python library PyVis. These chapters
are all designed to give you the essential background knowledge, terminology, and Python
code to get started applying these libraries and methods on your own dataset.
Part V of the textbook will introduce the reader to app development with the Streamlit
library. Readers will gain an understanding of the basics of Streamlit and how to leverage its
components to create custom apps within just a few hours that can be hosted in the cloud.
The purpose of this part is to help the reader take an idea from concept to reality in as short
of time as possible.
After completing this textbook, you will have a strong enough command of Python to
begin leveraging it in your own projects. You will also have a broad exposure to different
ways that Python can be applied to humanities-based problems. Finally, you will have the
resources necessary for continuing your education.
Online Version
The print version of this textbook also has a free online component compiled as a Jupyter-
Book. As the libraries and methods discussed in this textbook advance, the print version
of this book will not be easily updated without new editions; the online version, however,
will be updated and maintained. If a section of code quits working because something has
changed with Python or one of the libraries used in this textbook, the online version will be
Preface xvii
corrected. If you notice that there is a problem with code, you can also formally submit an
issue or suggest an edit on GitHub so that it can be updated. These can be minor issues from
typographical errors, the need for greater explanation in a specific area, or problems with
code not working. To submit a GitHub issue, you can use the GitHub icon in the top-right
corner of the online version of this book.
Acknowledgments
This Python Textbook was created during my postdoctoral fellowship at the Smithsonian
Institution’s Data Science Lab with collaboration at the United States Holocaust Memorial
Museum. It would not have been possible without the help of Rebecca Dikow, Mike Trizna,
and those in the Data Science Lab who listened to, aided, and advised me while creating
these notebooks. I would also like to thank the content experts at the United States Holocaust
Memorial Museum (USHMM), specifically Michael Haley Goldman, Michael Levy, Robert
Ehrenreich, and Silvina Fernandez-Duque.
I would also like to dedicate this book to my wife, Stephanie Mattingly. She has been a
constant source of encouragement while I wrote this book in all its stages. She also always
encouraged me to pursue data science as a career path. Without her constant guidance, this
book would not have been possible.
xix
About the Author
William Mattingly is a 2022 Harry Frank Guggenheim Distinguished Scholar and a 2022-
2023 ACLS Grantee for his work as co-principal investigator and lead developer for the
Bitter Aloe Project which examines testimonies of violence from South Africa’s Truth and
Reconciliation Commission. He is currently the Postdoctoral Fellow for the Analysis of
Historical Documents at the Smithsonian Institution’s Data Science Lab. Mattingly cur-
rently works on two projects at the Smithsonian. The first is based at the United States
Holocaust Memorial Museum (USHMM), where he is developing a robust pipeline of
machine learning image classification and natural language processing (NLP) models to
automate the cataloging of millions of images. At the Smithsonian, he is working on a proj-
ect connected to the American Women’s History Initiative. Here, he is developing machine
learning and heuristic pipelines with spaCy, a Python NLP library. This pipeline will iden-
tify women in Smithsonian documents and automatically extract knowledge about them
so that we can better understand the influential role women played at the Smithsonian.
xxi
Part I
DOI: 10.1201/9781003342175-2
4 Introduction to Python for Humanists
accurate. After all, most universities will be taking a cut of the grant money (sometimes up
to 30%), so they want to make sure they see the numbers first.
After this, the university will submit the grant. Depending on the granting agency, the
wait time can be anywhere from a few months to nearly a year. During this time, the digital
project will may not move forward much, if at all. Rather, it may sit in a holding period
while the PI waits to hear back.
When we look at this timeline, it means that from initial idea to the start of the project,
even in the ideal scenario, it can be realistically 2–3 years before the project begins. All of
this comes with a bit of a gamble as well. The PI believes in the idea, they have also gauged
the community to know that there is interest in it, and they have found a technical lead
who can do the job, but a lot can happen in 2–3 years. In that time, new developments in
the domain expert’s field may have altered the project trajectory (or, worst-case-scenario,
made it redundant). Further, new digital approaches/methods may mean that an entirely
new approach is necessary. This is especially common today if the project involves machine
learning, a field in which new advances are happening every week. In addition to this, the
technical lead may have taken a job elsewhere. (This does happen as they are not contracted
until the grant is received). Finally, there is no guarantee that funding agencies value the
idea. This means that the time spent designing the project conceptually and preparing to
get started could be entirely in vain.
By learning to code, you can often negate this entire process by testing your idea within
days or weeks. This means that you will be able to test the validity of the idea and potentially
even create a minimum viable product (MVP) that can be used to assist in obtaining
funding. An MVP is a working subset of a project to demonstrate its validity. For a digital
humanities project, this may mean a simple front-end application or a subset of the data
prepared a specific way. MVPs are quite common today in places such as Silicon Valley,
where MVPs are used to present an idea to investors. This helps give a real sense of how the
project will work. While not all mechanics will be available in an MVP, it is a good proof-
of-concept. It also demonstrates that the project is possible, the team can do the work they
are promising, and that the team already has a good handle of the potential issues that may
surface. These are all things that granting agencies like to see. Throughout this textbook,
you will develop the skills necessary to create an MVP that you can present to a granting
agency. This is especially true with the final chapter, where we learn how to build cloud-
based Python applications with Streamlit.
Another issue that vanishes is the lag time from idea to execution. Once a funded project
begins, the PI will guide their vision and convey each step to the technical lead whose job it is
to make that vision a reality. There is a lag that exists here. Often, meetings on digital projects
occur on a regular basis, sometimes weekly or bi-weekly. During that time, issues may
surface that are placed on hold until the next meeting. This can put a digital project behind
schedule. If the humanist is self-reliant, however, they can develop their idea independently
of a technical lead. This means that when an issue surfaces, the PI can immediately rectify
it and communicate the solution to the technical lead.
Third, technical leads on projects usually absorb a lot of funding. Hiring a programmer
can be costly, but if your project requires data science and machine learning, experts in these
areas can costs hundreds of dollars per hour. If the PI has the technical expertise, they can
perform technical aspects of a project until enough money is received to hire a technical
lead.
If you could, would your results be good? To answer the former, yes, if you are willing
to spend months doing it; to answer the latter, likely not. Programming allows for you to
develop programs that perform all these tasks across all 5,000 documents. When you run a
search, you will not simply hit ctrl+f. You will code your own search method so that your
simple search can return very complex results that accounts for variance in the text.
Python makes all of this possible.
1. C
2. Python
3. JavaScript
4. R
5. HTML (this is debatable)
Not all programming languages are created equal. Some are best used for developing
software, such as C; others are best suited for web development, such as HTML and
JavaScript. And others are great at statistical analysis, R (and Python). Where does Python
excel? Python excels in many areas. One thing that sets it apart from other programming
languages for new coders is that it is easy to read and easy to write.
It is relatively easy to write compared to other programming languages because the
syntax, or way in which you write tasks in code, is straightforward. It is easy to read because
Python uses forced indentation. This means that blocks of code that can be difficult to read
in other programming languages are easily spotted in Python.
Since it’s creation in the early 1990s, Python has soared in popularity which has, in turn,
resulted in a large community of programmers and a large number of libraries available. We
will learn about libraries later in this textbook. For now, think of libraries as large quantities
of code that have already been written for you so that you can write one line of code to
perform a complex task that may take hundreds or thousands of lines of code to write.
Today, Python is one of the most widely used programming languages and is considered
the essential language for text analysis, machine learning, data analysis (alongside R), web
scrapping, and much more.
Python (as of this writing) is currently in version 3.11.0. Let’s break each of these
numbers down. The 3 refers to the main Python language. Python 2 still exists (in fact it
comes standard on all Macs), but it is no longer supported and is slowly being replaced
by Python 3. You should not invest time in learning Python 2 as it is only used to
support legacy software and has a high number of security issues due to its depreciated
status. This is important to note because certain things are coded differently between the
two programming languages. If you were to look for help on a coding forum, such as
StackOverflow, it is important to know about these distinctions.
The 11.0 in Python 3.11.0, tells us specifically what version of Python 3. Not all code
from certain libraries is backwards compatible, meaning some libraries require a specific
version of Python, so understanding this now as a concept will save confusion later. Each
time a new version comes out, new features are available, so it is important to stay up-to-
date with current versions, but it is not always essential.
Introduction to Python 7
1.2.1 Trinket
Throughout the digital version of the textbook, you will see Trinket applications embedded
within each page. Trinket allows you to practice your coding skills without ever installing
Python. If you are new to coding and want to get started immediately without installing
Python, I recommend working with Trinket inside the digital version of this textbook.
These will allow for you to practice the lesson right inside the digital textbook.
You will be able to write your code inside this Trinket application and then click the
play button at the top. This will execute your code and populate the results on the right
hand output.
increasingly difficult as they require libraries that are not supported by Trinket. At this time,
you will want to consider another option. Again, to delay the installation of Pyonn on your
machine, we can rely on other cloud-based alternatives.
There are two options for running this textbook’s code in the cloud outside of the
textbook: Google Colab and Binder (addressed below). In the top right corner of each page
is a rocket ship. If you hold your mouse of this rocket ship, you will have two options to
choose from, Binder or Colab. Click Colab.
FIGURE 1.1
Picture of Rocket Ship in Top-Right Corner of Online JupyterBook.
Once you click the Colab button you will be taken to Google Colab and see a Notebook
inside the Google Colab system that should look like this:
FIGURE 1.2
Demo of Google Colab Opened.
Introduction to Python 9
FIGURE 1.3
Demonstration of Rocket Ship in Top-Right Corner.
10 Introduction to Python for Humanists
FIGURE 1.4
Selecting the Binder Button.
At this stage, your screen should look like should look like this:
If it does, then sit back and relax. It may take a few minutes as Binder builds the
environment. Once Binder is finished, click on “File” in the top left corner of the screen
and then select “New Notebook”.
FIGURE 1.5
Creating a New Notebook in Binder.
After this, select “Python 3 (ipykernal)”. This will open a fresh, new notebook.
FIGURE 1.6
Selecting the Python 3 Kernal for the New Notebook.
Introduction to Python 11
Now you should have a new notebook that looks like this:
FIGURE 1.7
Example of a New Notebook Page.
And now, you can fully follow along with this textbook.
FIGURE 1.8
Creating a Jupyter Notebook Online.
12 Introduction to Python for Humanists
After that, you will see a screen that looks like this:
FIGURE 1.9
Binder Creating a New Environment for the Notebook.
After a few minutes, the environment will load and you should see a notebook. Click
“File” in the top left corner, New Notebook, and select Python (Pyodide).
FIGURE 1.10
Creating a New Notebook.
Introduction to Python 13
Once loaded, you can follow along with this textbook in the new notebook.
FIGURE 1.11
Example of a New Notebook.
FIGURE 1.12
Anaconda’s Homepage.
more sense. For now, simply understand that Anaconda Navigator and JupyterLab (both of
which we install in this chapter), make your start to learning to code much, much simpler.
FIGURE 1.13
Download Individual Edition.
FIGURE 1.14
The Anaconda Navigator Main User Interface.
1.2.6 Conclusion
If at any point in the installation process you get frustrated, do not get discouraged. You are
not alone and it is not a simple or easy process. Those who have been programming for years
can make these steps look simple, but troubleshooting issues on your own is challenging.
16 Introduction to Python for Humanists
FIGURE 1.15
How to Install Jupyter Lab.
Hello, William!
Introduction to Python 17
As we can see, the code that we typed in the Jupyter cell outputted beneath it. Now, it
is your turn. Try to print off something. In order to print off text, you will need to use an
open and a close quotation mark. We will learn more about this as we meet strings in the
next chapter.
<IPython.lib.display.IFrame at 0x7f0a6c7b3af0>
This has worked wonderfully, but what if our Python notebook needs to be more
dynamic, meaning it needs to adjust based on some user input. Perhaps, we need to use
a name other than William based on some user-defined input. To do this, we would need
to store a piece of data in memory. We can do this in Python by creating a variable that will
point to an object. Before we get into how this is done, let’s first get to know objects and
variables.
1.3.2 Objects
When we import or create data within Python, we are essentially creating an object in
memory with a variable. These two words, object and variable mean slightly different
things, but are often used interchangeably. We will not get into the complexities of their
differences and why they exist in this textbook, but for now, view an object as something
that is created by a Python script and stored in your computer’s memory so that it can be
used later in a program.
Think of your computer’s memory rather like your own brain. Imagine if you needed to
remember what the word for “hello” is in German. You may use your memory rather like
a flashcard, where “hello” in English equates to “hallo” in German. In Python, we create
objects in a similar way. The object would be the dictionary entry of “hello: hallo”.
1.3.3 Variables
In order to reference this dictionary entry in memory, we need a way to reference it. We do
this with a variable. The variable is simply the name of the item in our script that will point
to that object in memory. Variables make it so that we can have an easy-to-remember name
to reference, call, and change that object in memory.
Variables can be created by typing a unique word, followed by an “=” sign, followed by
the specific data. As we will learn throughout this chapter, there are many types of data that
are created differently. Let’s create our first object before we begin. This will be a string, or
a piece of text. (We will learn about these in more detail below.) In my case, I want to create
the object author. I want author to be associated with my name in memory. In the cell, or
block of code, below, let’s do this.
Excellent! We have created our first object. Now, it is time to use that object. Below, we
will learn about ways we can manipulate strings, but for now, let’s simply see if that object
exists in memory. We can do this with the print function.
The print function will become your best friend in Python. It is, perhaps, the function I
use most commonly. The reason for this is because the print function allows for you to easily
debug, or identify problems and fix them, within your code. It allows us to print off objects
that are stored in memory.
To use the print function, we type the word print followed by an open parentheses. After
the open parentheses, we place the object or that or piece of data that we want to print. After
18 Introduction to Python for Humanists
that, we close the function with the close parentheses. Let’s try to print off our new object
author to make sure it is in memory.
print(author)
William Mattingly
Notice that when I execute the cell above, I see an output that relates to the object we
created above. What would happen if I tried to print off that object, but I used a capital letter,
rather than a lowercase one at the beginning, so Author, rather than author?
print(Author)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 print (Author)
The scary looking block of text above indicates that we have produced an error in Python.
This mistake teaches us two things. First, Python is case sensitive. This means that if any
object (or string) will need to be matched in not only letters, but also the case of those letters.
Second, this mistake teaches us that we can only call objects that have been created and
stored in memory.
Now that we have the variable pointing to a specific piece of data, we can make our print
function above a bit more dynamic. Let’s try and print off the same statement as before, but
with the new full author name. I don’t expect you to understand the specifics of the code
below, rather simply understand that we will frequently need to store variables in memory
so that we can use them later in our programs.
print(f"Hello, {author}!")
Here is a list of the Python keywords. Enter any keyword to get more help.
[ArithmeticError,
AssertionError,
AttributeError,
BaseException,
BlockingIOError,
BrokenPipeError,
BufferError,
BytesWarning,
ChildProcessError,
ConnectionAbortedError,
ConnectionError,
ConnectionRefusedError,
ConnectionResetError,
DeprecationWarning,
EOFError,
OSError,
Exception,
FileExistsError,
FileNotFoundError,
FloatingPointError,
FutureWarning,
GeneratorExit,
OSError,
ImportError,
ImportWarning,
IndentationError,
IndexError,
InterruptedError,
IsADirectoryError,
KeyError,
KeyboardInterrupt,
LookupError,
MemoryError,
ModuleNotFoundError,
NameError,
(continues on next page)
20 Introduction to Python for Humanists
Of this long list, I recommend paying particular attention to the ones that you are more
likely to write naturally: bool, dict, float, int, list, map, object, property, range, reversed, set,
slice, str, super, tuple, type, and zip. You are more likely to use these as variable names by
accident than, say, ZeroDivisionError; and this shorter list is a lot easier to memorize.
str
1.3.8 Bugs
Throughout your programming career, you will often read or hear about bugs. A bug is
a problem in your code that either returns an error or an unintended result in the output.
Tracing down bugs and fixing them is known as debugging. Aside from figuring out how
to code solutions to problems, debugging can be one of the more time-consuming aspects
of writing a program, especially if it is quite complex. Throughout this textbook, we will
encounter common errors so that you can see them in this controlled space. We will also
walk through what the error means and how to resolve it. That said, you are likely to create
many other bugs as you try to apply the code in this textbook to your own data. That is
expected. Always remember to read each line of your Pyhon carefully and, if you have an
error message, identify where the error is coming from and what it is.
2
Data and Data Structures
In this chapter, we will be learning about data and data structures. As with any program-
ming language, it is important to have a basic understanding in these two concepts as
they are the building blocks for most things you will do in Python. Whenever you write
a program or do something with code, you are essentially writing commands to load, save,
interact with, and manipulate data in some way. Understanding the different types of data
and how to structure and store them is, therefore, essential.
• Strings (text)
• Integers (whole numbers)
• Floats (decimal numbers)
DOI: 10.1201/9781003342175-3
24 Introduction to Python for Humanists
2.1.2 Strings
Strings are a sequence of characters. A good way to think about a string is as text. We can
create a string in python by designating a unique variable name and setting = to something
within quotation marks, i.e., " " or "".
The opening of a quotation mark indicates to Python that a string has begun and the
closing of the same style of a quotation mark indicates the close of a string. It is important
to use the same style of quotation mark for a string, either a double or a single.
Let’s take a look at a few examples of strings.
Examples of Strings
In our first example of a string, we will name our first string object with the variable name
first_string. Notice that we are using an underscore (_) to indicate a separation of two
words in our variable name. This is common practice in Python. We cannot use a space in a
variable name. Another naming convention could be firstString, where the first word is
lower cased while the start of each sequential word is capitalized. This naming convention,
while acceptable, is more common in other programming languages, such as JavaScript.
first_string = "This is a string."
Now that we have created our first object, let’s try and print it off. We can do this using
the print function.
print(first_string)
This is a string.
Let’s take a look at another example. This time, however, we will use two ’.
second_string = 'This is a string too.'
print(second_string)
Let’s now take a look at a bad example of a string. In the example below, we will
intentionally try to create an error message by combining two different types of quotation
marks.
Input In [6]
bad_string = "This is a bad example of a string'
ˆ
SyntaxError: EOL while scanning string literal
long_string = '''
'''
print(long_string)
print(first_name.capitalize())
William
I will use this in niche circumstances, particularly when I am performing data cleaning
and need to ensure that all names or proper nouns in a dataset are cleaned and well-
structured.
multiple line breaks, hyphenated characters, the list goes on. The .replace() method
allows you to quickly and effectively clean textual data so that it can be standardized.
Unlike the above methods, for .replace(), we need to put two things within the
parentheses. These are known as arguments. This method requires two and they must be
in order. The first is the thing that you want to replace and the second is the thing that you
want to replace it with. These will be separated by a parentheses and both must be strings.
It should, therefore, look something like this:
.replace("the thing to replace", "the thing you want to replace it with")
In the example below, let’s try and replace the period at the end of “Mattingly.”
print(introduction.replace(".", ""))
Excellent! Now, let’s try and reprint off introduction_sentence and see what
happens.
print(introduction)
Uh oh! Something is not right. Nothing has changed! Indeed, this is because strings are
immutable objects. Immutable objects are objects that cannot be changed in memory. As we
will see in the next chapter with lists, the other type of object is one that can be changed
in memory. These are known as mutable objects. In order to change a string, therefore,
you must recreate it in memory or create a new string object from it. Let’s try and do that
below.
print(new_introduction)
As with replace, split() is a method and, therefore, we use it with a “.” after the
variable name.
print(book_name.split())
Random documents with unrelated
content Scribd suggests to you:
95, 104.
Héliodore chassé du temple, tableau de Delacroix (chapelle des
Saints-Anges, à Saint-Sulpice), I, 411 note 479; II, 467; III, 350.
—Esquisse du même, III, 401.
Héliodore chassé du temple, tableau de Francesco Solimena, I, 203
note 208.
HENNEQUIN (Amédée), ami de Berryer, II, 353 et note 4, 358, 362,
363, 366, 368.
HENRI IV, II, 485.
Henri IV dans sa maison. petite toile de Delacroix, I, 311.
Henri IV, drame de Shakespeare, III, 424.
Héraclius, tragédie de Calderon, III, 320, 321
HERBAUT, I, 344, 372.
HERBELIN (Mme), peintre, II, 89 et note 1, 137, 157, 175;
III, 35, 130 et note 5, 132, 162, 184 et note 1, 396.
Hercule étouffant Antée, toile de Delacroix, II, 314 et note 3.
Hercule ramène Alceste du fond des enfers, tympan décoratif
de l'Hôtel de ville, par Delacroix, I, 216.
Hercule et Diomède, toile de Delacroix, II, 286 et note 4.
HERMANT (Adolphe), dit Hermann, violoniste, II, 314 et note 2.
Herminie et les bergers, toile de Delacroix, II, 291;
III, 143, 161 et note 1, 162, 362 note.
Hérodote interroge les traditions des Mages, peinture décorative,
de la bibliothèque du Palais-Bourbon, par Delacroix, I, 257.
Hésiode et la Muse, peinture décorative de la bibliothèque
du Palais-Bourbon, par Delacroix, I, 257.
HESSE (Nicolas-Auguste), peintre, III, 416.
HETZEL, libraire et littérateur, II, 269 et note 2.
HIPPOCRATE, II, 367; III, 177.
Hippocrate refuse les présents du roi de Perse, peinture décorative
de la bibliothèque du Palais-Bourbon, par Delacroix, I, 258.
HIS (Charles), publiciste, I, 271 et note 287.—(Mme), II, 342 et
note.
Histoire de la Révolution, par Michelet, I, 302.
Histoire de la vie et des ouvrages de Raphaël, par Quatremère
de Quincy, I, 108 et note 127.
Histoire de l'Égypte sous Méhémet-Ali, par Maugin, I, 108.
Histoire de ma vie, par George Sand, III, 34 et note 2.
HITTORF (Jacques-Ignace), architecte, III, 63 et note 4, 304.
HOGARTH (William), peintre et graveur anglais, III, 38, 41.
HOMÈRE, II, 72, 258, 260, 301, 302, 388; III, 240, 263, 272,
310, 348, 361.
Homme dévoré par un lion, toile de Delacroix, I, 351 et note 409,
357.
Hommes couchés, après le bain, I, 215.
Hommes jouant aux échecs, toile de Delacroix, I, 357.
HORACE, I, 75 note 87; III, 171, 254, 361.
Hortensias, toile de Delacroix, I, 347, 354.
HOUDETOT (le comte D'), administrateur et homme politique,
I, 137 et note 155; II, 313.
HOUSSAYE (Arsène), littérateur, II, 290 et note 1.
HUBER (Pierre), naturaliste suisse, III, 57 et note.
HUET (Paul), peintre paysagiste, II, 377 et note 1; III, 118
et notes 1 et 3, 323.
HUGO (Victor), liii, liv, I, 210 et note 215, 363, 371; II, 201, 302.
Huguenots (les), opéra de Meyerbeer, I, 268; II, 300, 301.
HUGUES (Henri), cousin de Delacroix, I, 9 note 11, 13, 19, 25, 58,
63, 71, 97, 255.
HUNT (William-Holmant), peintre anglais, III, 38 et note 3, 51.
Kaïd goûtant le lait que lui offrent les paysans, dessin à la plume,
de Delacroix, I, 214.
KALERJI (Mme), amie de Chopin, I, 359, 369, 371, 372, 431;
III, 86, 90, 91, 92.
KANT, philosophe allemand, II, 443.
KARR (Alphonse), littérateur, II, 213 et note.
KAYSER (DE), peintre, II, 411.
KERDREL (M. DE), homme politique, II, 488.
KIATKOWSKI, ami de Chopin, II, 223.
KLOTZ, architecte de Strasbourg, III, 83.
KNEPFLER, peintre, I, 278.
Knox le puritain prêchant devant Marie Stuart, esquisse de Wilkie, I,
196 note.
LABBÉ, I, 247.
LABLACHE (Mlle Mariette), cantatrice, II, 176 et note 3.
Labourage nivernais, toile de Rosa Bonheur, musée du Luxembourg,
I, 351 note 410.
LA BRUYÈRE, II, 182; III, 352.
Lac (le), poésie de Lamartine, I, 366.
LACÉPÈDE (DE), naturaliste, I, 239.
LA COMBE (le colonel DE), auteur d'un ouvrage sur Charlet,
III, 187 note 2, 371 note 2.
LACROIX (Gaspard-Jean), peintre paysagiste, I, 288 et note 320,
289,
291, 307 et note 352.
Lady Macbeth, toile de Delacroix, I, 377 et note 450.
LAFONT (Émile), peintre, I, 431 et note 497.
LA FONTAINE, II, 51, 216, 390, 396, 440; III, 171.
LAGNIER, III, 166.
LAGUERRE (le docteur), III, 276, 277, 284, 288, 290, 291, 304,
318, 433 et note 2.
LAITY, ancien lieutenant d'artillerie, II, 314 et note 1; III, 118.
LAJUDIE (Mme DE), fille aînée du baron Rivet, III, 65 et note, 404.
LAMARTINE, I, 87, 91, 346, 367, 415; II, 347 et note, 348, 396;
III, 110, 348, 397.
LAMBERT (Eugène), peintre, II, 87 et note 1.
LAMBERT (Mme), fille de M. Bornot, I, 403 note 471.
LAMEY, cousin de Delacroix, I, 75 note 86; III, 81 et note, 82, 93,
96,
132, 163 et note 5, 161, 165, 277, 278, 289, 294, 335, 336,
413, 416.—(Mme), I, 105; III, 83, 85, 86, 96, 132.
LAMEY (Ferdinand), III, 85.—(Mme), III, 148.
LAMORICIÈRE (le général), I, 447 et note 503; II, 364.
LAMY (Eugène), peintre et dessinateur, II, 174 et note.
LANDON (Paul), peintre et littérateur, II, 401 et note.
LANGLOIS (Jean-Charles), peintre, III, 324 et note 2.
LANTON, III, 86.
LAPORTE (M DE), consul de France au Maroc, I, 150 et note 168.—
(Mme), I, 394.
LARCHEZ, I, 105.
LARIBE, I, 30.
LA RIVE, tragédien, I, 272.
LARIVIÈRE,peintre, II, 311 et note 2.
LARREY (le baron), chirurgien, I, 286 et note 316.
LAS MARISMAS (Mme), III, 297.
LASSALLE (Émile), peintre, élève de Delacroix, I, 274 et note 297,
290;
II, 87 note 1; III, 174 et note 3.
LASSALLE-BORDES, peintre, élève de Delacroix, I, 260 note 267,
261;
III, 167 note.
LASSUS (J.-B.-Antoine), architecte, I, 343 et note 399; II, 177.
LASTEYBIE (le comte DE), archéologue, II, 152 et note 2.
LATOUCHE (Henri DE), littérateur, III, 34 et note 3.
LATOUR (Maurice-Quentin DE), pastelliste, III, 169 et note 3.
LAUGIER (Jean-Nicolas), graveur, I, 130 et note 144.
LAUGIER (Stanislas), chirurgien, I, 306 et note 349.
LAURE, modèle, I, 92, 93, 104, 130, 131.
LAURENCEAU(Baron), ami de Berryer, II, 487, 490.—(Baronne), II,
487.
LAURENS (Joseph-Bonaventure), littérateur et compositeur, I, 326 et
note 383.
LAURENS (Jules), peintre, lithographe et graveur, I, 326 et note 383,
424 et note 491; II, 37.
LAVALETTE (le comte DE), III, 45 note, 46, 173.—(Mme DE), II,
391;
III, 45 et note.
LAVOYPIERRE, cuisinier, II, 483.
LAWRENCE, peintre anglais, II, 162 et note 1; III, 36 note, 38, 69,
216, 377.
LEBLOND (Frédéric), ami de Delacroix, I, xiii; I, 43 et note 49, 53,
72, 66, 69, 71, 72, 74 à 76, 82, 90, 91, 94, 96, 102, 103, 107,
117, 124, 127, 129, 130, 132, 135 à 139, 247, 281, 290, 307,
308, 317, 318, 354, 369.—(Mme), I, 282, 308, 354.
LEBORNE (Joseph-Louis), peintre, I, 92.
LEBOUC (Charles), violoncelliste, III, 131 et note 2.
LÈBRE, archéologue, III, 363.
LEBRUN (Charles), peintre, I, 368; II, 91, 173, 315; III, 119, 248,
252, 291.
LECOMTE (Hippolyte), peintre, II, 76 et note 1.
LECZINSKI (Stanislas Ier), roi de Pologne, III, 278, 279,
280, 281, 283.
Léda, fresque de Delacroix, à Valmont, I, 193 et note 196.
LEDRU (Hilaire), peintre, III, 395 et note 3.
LEDRU DES ESSARTS (le général), voisin de campagne de Delacroix,
à Champrosay, I, 445 et note 499.
LEDRU-ROLLIN, homme politique, II, 376.
LEFEBVRE, marchand de tableaux, I, 357 et note 418.
LEFEBVRE (Charles), peintre, I, 290 et note 322; II, 292.
LEFEBVRE (Jules), peintre, III, 289 et note.
LEFÈVRE-DEUMIER, littérateur et poète, II, 314 et note 6, 386;
III, 120 et note 1.—(Mme), sculpteur, II, 314 et note 6; III, 120.
LEFRANC, marchand de couleurs, I, 316; II, 411.
LEFUEL, architecte, II, 229 et note 2; III, 10, 26, 135.
LEGENDRE, III, 410.
Législation (la), peinture décorative de la bibliothèque
du Palais-Bourbon, par Delacroix, I, 257.
LEGOUVÉ (E.), auteur dramatique, III, 20.
LEGRAND, ami de Berryer, III, 292.
LEGRAND (Mme Pierre), fille de M. Bornot, I, 403 note 471.
LEGROS (Pierre), sculpteur, II, 129 et note 2.
LE GUILLOU (Jenny), gouvernante de Delacroix, I, 256 note 257,
315 et note 365,
383, 406, 434, 442, 444; II, 1, 15, 25, 103 et note, 123,
134, 185, 186, 202, 210, 228, 842, 247 et note 1, 256, 169,
286, 328 à 331, 333, 336, 380, 387, 411, 417, 425, 427, 430,
438, 447, 477, 492; III, 24, 29, 93, 101, 103, 104 et note.
105, 107, 108, 132, 145, 101, 179, 180, 266, 269, 272, 278,
284. 288, 304, 347, 409, 433 et note.
LEHMANN, peintre, II, 81 et note 1, 89, 106, 295.
LEHON (Mme), II, 378.
LEHON fils, II, 378,
LEIBNITZ, philosophe allemand, II, 442.
LELEUX (Adolphe-Pierre), peintre, I, 235 et note 229, 253, 302.
Lélia, toile de Delacroix, I, 324, 332 et note 387.
LELIÈVRE, peintre, I, 46, 53, 56, 57, 75, 84, 99, 105, 106.
—Mme, I, 54, 55, 92.
LEMAITRE (Frederick), acteur, II, 201 et note.
LEMERCIER (Népomucène), littérateur, I, 81, note 96.
LEMOINNE (John), journaliste, III, 108 et note 1.
LEMOLE (M.), amateur, I, 93.
LENOBLE, homme d'affaires de Delacroix, I, 297, 328, 335.
LENORMANT (Charles), archéologue et historien, III, 344 et note 1.
LÉON X (le pape), II, 377.
Léonore, opéra de Beethoven, appelé aussi Fidelio,
I, 297 et note 334, 417.
LÉOTAUD (Mme DE), III, 5.
LEQUIEN fils, dessinateur, III, 68.
LERMINIER, publiciste, I, 317.
LEROUX (Eugène), lithographe, III, 164 et note 1.
LEROUX (Jean-Marie), graveur et dessinateur, III, 160 et note 2.
LEROUX (Pierre), publiciste, I, 325 et note 382; III, 2 note 3.
LEROY (F.), III, 150.
LEROY D'ETIOLES, chirurgien, III, 350.
LESAGE, peintre, II, 396.
LESAGE, romancier, III, 360.
LESLIE (Charles-Robert), peintre anglais, III, 37 et note 1.
LESPINASSE (Mlle DE), femme de lettres, III, 428.
LESSERT (Mme DE), III, 331.
LESSORE (Émile-Aubert), paysagiste, I, 311 et note 360, 335.
LESUEUR, peintre, I, 203, 300, 304; II, 63, 64, 91, 129, 171; III,
253.
Lettre sur les spectacles, de J.-J. Rousseau, II, 407.
Lettres sur l'Egypte, par Savary, I, 107 et note 125.
—Sur la Grèce, I, 107, note 125.
LEVASSOR, acteur comique, II, 419 et note 2; III, 21 et note 1.
LEVEL, sculpteur, II, 495.
LEYGUE, peintre, élève de Delacroix, II, 87 note 1.
LEYS (Henri), peintre belge, II, 30 et note; III, 39.
LEWIS, romancier anglais, I, 213 et note 216.
LHÉRITIER (le docteur), III, 345 et note 1.
Liberté de 1830 (la), toile de Delacroix, musée du Louvre, I, 337.
Lion (le), gravure de Denon, I, 296.
Lion (un), tableau de Delacroix, I, 234 note 226.
Lion (un), pastel de Delacroix, I, 239.
Lion(le petit), tableau de Delacroix, II, 418
Lion dans les montagnes, toile de Delacroix, II, 61.
Lion guettant sa proie, tableau de Delacroix, II, 292 et note.
Lion (un), toile de Van Thulden, à Bruxelles, II, 8.
Lion et le Sanglier (le), toile de Delacroix, II, 137.
Lion et l'Homme mort (le), toile de Delacroix, I, 291, 293, 301.
Lion terrassant un sanglier, toile de Delacroix, II, 138.
Lions, deux toiles de Delacroix, II, 340 et note 1; III, 137, 143.
Lions (deux), toile de Delacroix, II, 138.
LISETTE, paysanne du Louroux, I, 2, 4, 5, 6, 14.
LISZT, pianiste et compositeur allemand, I, 288 note 319; II, 47; III,
68 et note 1.
Loges du Vatican (les), I, 79 note 92.
LONCHAMPS (Pierre-Charpentier DE), littérateur, III, 392 et note 1.
LOPEZ ou LOPÈS, peintre, I, 27 note 36, 45, 53, 72, 75, 104.
LORD-MAIRE de Londres (le), III, 30, 31.
Loth, toile de Rubens, musée du Louvre, II, 388.
Louis XIV, III, 5.
Louis XVI, II, 350, 376.
LOUIS-PHILIPPE, I, 79 et note 93, 171.
Louroux (le), propriété du général Charles Delacroix, en Touraine, I,
1.
Louvois, III, 5.
LUCAS DE LEYDE, maître hollandais, I, 386; II, 4 et note; III, 226.
LUCCA DELLA ROBBIA, sculpteur florentin, II, 437.
Lucrèce et Tarquin, toile de Titien, I, 273.
Lucrezia Borgia, opéra de Donizetti, II, 281 et note 2, 293, 302.
LULLI, musicien et compositeur, III, 13.
Lumière du monde (la), toile de Hunt, III, 38 note 3.
LUNA (Ch. DE), peintre, II, 94.
Lutte de Jacob avec l'ange (la), peinture décorative de la chapelle
des Saints-Anges, à Saint-Sulpice, par Delacroix, I, 411 note 479.
Lycurgue consulte la Pythie, peinture décorative de la bibliothèque
du Palais-Bourbon, par Delacroix, I, 257 note 260, 261 note 267;
II, 92.
LYONNE (M. DE), I, 272.
ebookbell.com