Python console persistence with saving? Display manual edits as Python commands?

If I define a variable in the python console, then save my file, is that variable lost the next time I start up the file?

Suppose I have a group of 25 objects among 150. I want to group them because it’s easier to get right at them then messing with indexing on bpy.data.objects (especially if they’re non-contiguous). It’s looking like this isn’t possible with simple python variables, but it also seems like a common sort of issue, so I imagine there’s a ‘grouping’ solution. Any advice?

EDIT: this is completely unrelated, but rather filling up the front page with questions I’ll just ask here & change the title. Is there a way to have the text editor or python console display the commands used as I work in the regular UI? For example, if I were to click & change the frame the console would spit out bpy.context.scene.frame_set(40) or something similar? This seems like an ideal way to get up to speed on the API instead of ctrl+f-ing my way through the docs.

Yes, local console variables are lost whenever the console restarts. To save them and make them persistent, load them from an external TXT or CSV file.

This free add-on has the option to display every Python operator you use on-screen, it’s not in the console but other than that it’s exactly what you’re describing: