Search code examples
pythonargvsys

Can anyone clarify something about the sys module and the nature of variables?


Its simple.sys.argv is a list which I assigned to a variable. Sys.argv varies with user input. Would the variable change with it as well? I know this like going deep into tiny details but i really could use some help.

import sys
list=sys.argv

Solution

  • The variable will not change unless you reassign it to sys.argv. Variables do not magically change based on their assignment unless they share memory locations. sys.argv is a list (mutable) so there is no reason it should or would share a memory address with list.

    Which brings us to another point: if sys.argv is already a list, why would you store it in a different list variable? (hint: you wouldn't)