11/19 Efficiency?


I noticed the code for this is

import math # Imports the math module
everything = dir(math) # Sets everything to a list of things from math
print everything # Prints 'em all!

For real world programming, if you want to find a directory or as such, wouldn't it be more efficient to print the code like this?

import math # Imports the math module
print dir(math) # Prints a directory list from the math library

I don't understand too much about programming (yet), but does creating a unique function for it first have any type of benefits when it comes to larger programs?


Variables are useful when you want to use a value multiple times.
If you're just using it once, then no, you don't need to store it in a variable first.

In terms of efficiency it doesn't matter, variables are cheap. But code is not cheap, so write whichever is more readable.