I'm watching Billy Wilder's The Apartment (1960), and when Jack Lemmon's character picks up the phone, he dials 3 numbers, then tells and operator the name and location of the person he wants, who then connects them.
I've seen this in a bunch of old movies. Was the operator just a phone book service if you didn't know someones number? Did it cost extra? Did people not even have phone numbers? And at what point did operators cease to become a thing, and what did that transition look like?
What you saw happening in The Apartment was the character dialing 2-1-1 to reach "Long Distance [operator]," because he wanted to call another city. This is a minor plot point in Rear Window, where Jimmy Stewart's character can tell, even through binoculars, that the murder suspect dials only three digits, thus he must be placing a long distance call.
Originally, all phone users had to tell an operator whom they wished to call. In 1879, fearing a shortage of operators due to a measles epidemic, phone numbers were introduced in Lowell, Mass. They quickly became popular, allowing switchboard operators to quickly connect calls with little training, and spread nationwide by 1910.
In 1891, Almon Strowger invented automated exchange equipment that could interpret interruptions in the phone line's current as digits and use a system of stepping relays to connect to another local line. At first, Strowger's exchange equipment was a competitive advantage adopted by upstart "Automatic" competitor phone companies in big cities, and by small-town telcos looking to save money, but the Bell System developed its own automated exchange equipment by 1919 and by 1935 most urban phone subscribers could dial their own local calls. Very small communities continued to have switchboards into the 1970s, and as heard in The Andy Griffith Show, it wasn’t uncommon to ask to be connected to another party by name rather than number. The nation's last manual exchange was claimed to be in Bryant Pond, Maine, automated in 1983.
The telephone network was always an affiliation of hundreds of independent companies. By the Great Depression, almost all cities had only a single telephone company—but many remained independent of the Bell System, particularly in rural areas. General Telephone gradually purchased a number of small-city telcos, and there were other regional multicity companies. Rural areas that offered little chance for profit eventually established telephone cooperatives with help from the New Deal’s Rural Electrification Administration. The majority of intercity phone circuits, however, were operated by the Bell System’s Long Lines Division. Until the 1960s, placing a long distance call meant first contacting a local operator by dialing 0 or 2-1-1. An operator would then arrange the long-distance circuit, calling you back when it was ready. Beginning in the late 1940s, big-city operators could put long-distance calls though using a process similar to Touch-Tone dialing, and connect the parties within a few seconds.
Direct Distance Dialing was introduced in 1951 and expanded quickly through the Bell System, using the North American Numbering Plan of unique numbers for every line, and had become the norm by 1965 in nearly all cities. This could only be used for “caller-pays” calls, however, and long distance was still expensive enough for midcentury movie audiences to understand the meaning of “but he’s calling long distance.” For collect or Person-to-Person (you only paid if connection to a specific person is made) calls, users still dialed 0 for Operator. Once again, however, rural areas lagged behind, and Direct Distance Dialing probably never became available to every landline across the country.
How did you get the phone number of someone in a distant city? You had the operator get it for you, via the same long-distance circuits they'd use to complete the call. (Actually, you could just ask for "Spade and Archer" in San Francisco; I don't remember if the operator gave you the number for future reference or just put the call through.) Public libraries often had collections of phone books, but those were used for research, such as writing to all the banks in a distant city seeking a job.
By the early 1970s, the Bell System had rolled out direct-dialed Directory Assistance. You'd dial the area code of the distant city (there was a map in the front of the phone book, as the runaway boy is seen clutching in Secondhand Lions) plus 555-1212, and ask that remote operator—her first question would be "what city?" or "which borough?" if you called 212 for New York—for the business or family you wanted to reach. These clerical workers just paged through phone books all day, and didn't have outgoing phone lines with dials. As a high-school phone prankster in the 1970s, friends and I would rig together two phone lines and call Directory Assistance operators in two distant cities, then listen in as they tried to puzzle out how they'd gotten connected to each other. When I chose a name for my custom cartography business in the 1990s, I included the word "Chicago," figuring that if someone couldn't figure out what city's directory assistance office to call based on the firm's name, I wasn't going to be very happy doing work for them.