Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Python equivalent of PHP's var_dump()? [duplicate]

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?

like image 532
Zoredache Avatar asked Dec 21 '08 00:12

Zoredache


People also ask

What is the difference between Var_dump () and Print_r ()?

var_dump() displays values along with data types as output. print_r() displays only value as output. It does not have any return type. It will return a value that is in string format.

Why Var_dump () is preferable over Print_r ()?

It's too simple. The var_dump() function displays structured information about variables/expressions including its type and value. Whereas The print_r() displays information about a variable in a way that's readable by humans. Example: Say we have got the following array and we want to display its contents.

What does Var_dump mean?

The var_dump() function is used to dump information about a variable. This function displays structured information such as type and value of the given variable. Arrays and objects are explored recursively with values indented to show structure.


1 Answers

I think the best equivalent to PHP's var_dump($foo, $bar) is combine print with vars:

print vars(foo),vars(bar) 
like image 161
Jan Avatar answered Oct 09 '22 17:10

Jan