/python

@DHRI-Curriculum Session on Python, a general-purpose programming language used for a wide variety of computational tasks.

Creative Commons Attribution Share Alike 4.0 InternationalCC-BY-SA-4.0

Header image for the Python workshop

Python is a general-purpose programming language suitable for a wide variety of tasks in the digital humanities. Learning Python fundamentals is a gateway to analyzing data, creating visualizations, composing interactive websites, scraping the internet, and engaging in the distant reading of texts. This workshop first introduces participants to core programming concepts such as data types, variables, and functions. Participants will then learn about basic control flow by writing small programs with loops and conditional statements. They will also learn to problem solve, and practice searching for answers and debugging scripts. The workshop wraps up by exposing participants to intermediate tools for further exploration.

In this workshop, you will:

  • Understand what Python is and, in general terms, what it can do.
  • Run Python programs, both by interacting directly with the interpreter and by preparing and running scripts.
  • Distinguish among five core data types—integers, floats, strings, booleans, and lists.
  • Become familiar with core programming concepts, including variables, loops, and conditionals.
  • Engage with error output and use the internet and documentation to independently research language features.
  • Learn how to find and import code from external sources to solve more complex problems.

This workshop is estimated to take you 3-4 hours to complete.

Get Started


Lessons

  1. Interacting with Python
  2. Types
  3. Variables
  4. Running Scripts
  5. Errors in Python
  6. Functions
  7. Lists
  8. Loops
  9. Conditionals
  10. Input
  11. Doing Things to Lists
  12. Finding Answers with Google
  13. A Little Motivation
  14. Objects in Python

Before you get started

If you do not have experience or basic knowledge of the following workshops, you may want to look into those before you start with Introduction to Python:

  • Introduction to the Command Line (required) This workshop makes reference to concepts from the Command Line workshop, and having basic knowledge about how to use the command line will be central for anyone who wants to learn about programming with Python.
  • Installing Anaconda (recommended) You can use any installation of Python (but make sure it is of version 3) but for our purposes, Anaconda will provide everything necessary for all the workshops that are part of the DHRI curriculum.

Ethical Considerations

Before you start the Introduction to Python workshop, we want to remind you of some ethical considerations to take into account when you read through the lessons of this workshop:

  • Python works by reducing data to portable units and presenting them in a way that prioritizes readability. These units are known as "data types" and include strings (words/letters), integers (numbers), booleans (true or false statements), and lists (groups of strings). The python grammar, which dictates how python statements ought to be ordered, values simplicity, efficiency, and concision. You can read more about python values at the Zen of Python.
  • As we learn about the python data types and grammar, keep in mind that working within any digital format requires making seemingly neutral choices that carry ethical consequences. When using python, be aware of the ways the ways that data is transformed into computable form. What choices are you making about your data? What is being included, and what is left out? What are reductions and assumptions necessary to encode your data? If you are more interested in thinking further about data types and our choices in relation to data, you should have a look at our Data Literacies workshop.

Pre-reading suggestions

Before you start the Introduction to Python workshop, you may want to read a couple of our pre-reading suggestions:

Projects that use these skills

You may also want to check out a couple of projects that use the skills discussed in this workshop:

  • Built by former Digital Fellow Patrick Smyth, The NEH Impact Index makes visible the distribution of funds by National Endowment for the Humanities across the United States. The website uses python to map projects, communities, and cultural institutions who have received NEH support. You can check out the code on Github.
  • Mapping Arts NYC, created in 2019 by the Graduate Center's Data for Public Good fellows, "is a project that explores the geography and representation of arts and culture in New York City over time." It includes a number of Python scripts written to clean and make sense of all the data.
  • Python programmers build and maintain various "libraries," or collections of python code, that can be re-purposed toward custom projects. You might check out the Scrapy library for web scraping, the NumPy library for numerical computing, or the pandas library for data analysis and manipulation. Check out the individual websites to help you think about the data that you want to work with.

Get Started


Acknowledgements

This workshop is the result of a collaborative effort of a team of people, mostly involved presently or in the past, with the Graduate Center's Digital Initiatives. If you want to see statistics for contributions to this workshop, you can do so here. This is a list of all the contributors:


Digital Research Institute (DRI) Curriculum by Graduate Center Digital Initiatives is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Based on a work at https://github.com/DHRI-Curriculum. When sharing this material or derivative works, preserve this paragraph, changing only the title of the derivative work, or provide comparable attribution.

Creative Commons License