Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19k points)

When debugging in PHP, I frequently find it useful to simply stick a var_dump() in my code to show me what a variable is, what its value is, and the same for anything that it contains.

What is a good Python equivalent for this?

1 Answer

0 votes
by (106k points)

The best Python equivalent of PHP's var_dump() is to combine print with vars:

print vars(foo),vars(bar)

Another important method if you want to display the value nicely, you can use the pprint module. The easiest way to dump all variables with it.

from pprint import pprint

pprint(globals())

pprint(locals())

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Sep 26, 2019 in Python by Karan Singh (4.1k points)
0 votes
1 answer
asked Sep 26, 2019 in Python by Karan Singh (4.1k points)

Browse Categories

...