Which of the following is better to use and why?
Method 1:
for k, v in os.environ.items():
print \"%s=%s\" % (k, v)
Method 2
I find the first example better - less verbose, clearer and more readable.
In my opinion, go with what best gets your intention across, after all:
Programs should be written for people to read, and only incidentally for machines to execute.
-- from "Structure and Interpretation of Computer Programs" by Abelson and Sussman
By the way, since you're just starting to learn Python, start learning the new String Formatting syntax right away:
for k, v in os.environ.items():
print "{0}={1}".format(k, v)