How to effectively teach strings and string literal constants? I am teaching a general introductory CS course to 18-19 year olds, with Python3 as a support language, and I am not satisfied with how some students respond to strings and string literals. That is some of them struggle to understand when you should use quotes and when not.

For example, when trying to open a file, they will write open(/the/path/to/the/file) instead of open("/the/path/to/the/file") and fail to correct themselves. This is just an example ; the question is not about file/filename confusion.

Conversely, some students, when asked to write a function a parameter of which is a string, will write

def example("s") :
   #etc


There seem to be an underlying poor understanding of what a variable (or identifier) is. However these students are generally coping with programs that do not manipulate strings.

A related question (maybe I should post this one separately) is about the pros and cons of introducing strings before arrays/lists or the converse.

Some background

This takes place in France, in the CPGE (Classes préparatoires aux Grandes Écoles), a two-year curriculum that students may enroll in at the beginning of higher education (post-baccalauréat or post-A level or equivalent) but is physically located in high schools (lycées) and prepare students for national competitive exams (concours).

As a result, the global content of the course is mandated nationwide (including the use of Python3 as an example language) ; I can only choose the order and the manner in which I teach things. The course is mandatory for students but is not the main field of the curriculum (I have 1hr/week of blackboard course and 1hr/week lab session, compared to 10 to 12 hr/week of math and 8 to 10 hr/week of physics).

Computer science is not taught in France before university/higher education. There is only some algorithmics, taught by math teachers as well as they can, using pseudo-language and calculators languages, and not dealing with any data structure (only numbers) and no functions. So I start from zero.

Even in CPGE, the idea of teaching CS as a field in itself is quite new and not universally accepted. As a result, the nationwide CS curriculum for CPGE mandates that problems and examples should be taken from math and physics situations, which leads to string being scarcely used except for file names and data input from files (csv). Yet any concours may ask a problem about strings, since they are mentioned in the nationwide curriculum.
Perhaps the place to start is with a discussion of variables and making the distinction between a "thing" and a "name for the thing." 

A pretty good place to start that conversation is with the a poem from Through The Looking Glass, the sequel to Lewis Carroll's Alice in Wonderland.


The song's name is called Haddocks' Eyes
The song's name is The Aged Aged Man
The song is called Ways and Means
The song is A-sitting on a Gate


See wikipedia for a discussion and background as well as the poem itself.

In programming we don't normally use the first of these four distinctions, but the others are important. The second is how we think of a variable - a name for a thing. The fourth is the thing itself. The third can be an alias or alternate name for the thing, though that analogy isn't perfect. 

But once the distinction between the name and the thing is made, you have a better chance of winning. But you still need to be clear. 

"foo" is a thing (a String thing)
s = "foo" establishes s as a name for that thing. 

"s" is a different (String) thing. 

But "/the/path/to/the/file" is simultaneously a thing (String) but also a complicated name for another thing (a File). The open method needs a name for the file to be opened. 

Note that much of the above was copied from an essay I wrote in meta.