python
Python Code
"x
SyntaxError: unterminated string literal (detected at line 1) (20073044.py, line 1)
April 8, 2024
When talking about “Python” or other programming langauges, we often engage in a form of polysemy1 that can be confusing at first. I’ll try to unpack the different meanings here.
When we talk about “Python”, one thing we sometimes refer to is an abstract set of rules for a formal language.
When you say:
I’m learning Python this semester.
You’re talking about the abstract set of rules.
We can describe some of these rules in natural language (this isn’t how they’re actually written).
[0]
, return the first value in the list.print(
is followed by a value or variable, which is then followed by )
, print the value, or the value assigned to the variable.#
symbol is encountered on a line, ignore everything following it.These rules define very precisely how code should be written, and also define what should be done when certain patterns of code are encountered, but these rules are abstract, and don’t actually do anything.
Simply having a set of abstract rules can be fun, but it’s not so useful if you have no way to actually do things. To make code we write actually do anything, we need to use a program called an Interpreter.
When you say
I’m having a hard time installing Python.
you’re talking about a Python Interpreter.
The Python interpreter processes code, determines whether or not it is valid, then does the things the code told it to do.
Code can get passed to the interpreter many different ways, including
.py
)For example, the text in the shaded block below was passed to a Python interpreter, and the interpreter decided that it was invalid (because there is an opening quote "
, but not a closing quote).
SyntaxError: unterminated string literal (detected at line 1) (20073044.py, line 1)
The text in this next shaded block was passed to a Python interpreter. This time, it was deemed valid, and the interpreter did what the code instructed.
People often say that Python comes “with batteries included”, meaning it can do a lot of different things out without needing to install any extensions. But you can install extensions in the form of additional libraries that extend Python’s capabilities.
When someone says
Python is the most widely used language in natural language processing.
They are talking about the ecosystem of libraries for Python hat have been built to do natural language processing.
Some examples of additional libraries for Python are
numpy
: Allows for effective computation with numbersmatplotlib
: Makes graphsThe meanings of “Python” we’ve already talked about are
Understanding how to put all of these pieces together effectively is a social project.
When you say
So-n-so is really good at Python.
You are talking about their involvement in the Python social project.
In order to know newest or most effective way to do things, you need to be involved in 🧑💻 the social project. That begins within a classroom, then extends to keeping up with blogs and other discourses about changes and developments.
One way people demonstrate that they are involved in the Python social project is by writing their code idiomatically. For example, in the code block above, I included the line import numpy as np
. But there’s no rule that we import numpy
as np
, it’s simply convention.
This code below will run just as well, but would cause problems for people trying to read your code, because it’s not idiomatic.
It’s ok just say “Python” when you’re talking about one specific meaning.
A word is polysemous when it has more than one meaning.↩︎
@online{fruehwald,
author = {Fruehwald, Josef},
title = {What *Is* {Python?}},
url = {https://lin511-2024.github.io/notes/concepts/01_what-is-python.html},
langid = {en}
}