Print variable types: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
No edit summary
Line 2: Line 2:


== Print the type of the variable ==
== Print the type of the variable ==
=== PHP ===
PHP gettype()<ref>[http://php.net/manual/en/function.gettype.php PHP: gettype - Manual]</ref>:
PHP gettype()<ref>[http://php.net/manual/en/function.gettype.php PHP: gettype - Manual]</ref>:
<pre>
<pre>
Line 11: Line 12:
</pre>
</pre>


=== Python ===
Python type():<ref>[https://docs.python.org/3.6/library/functions.html?highlight=type#type type]</ref><ref>[https://waoewaoe.wordpress.com/2009/05/18/type-cast-variable-to-string-in-python/ Type cast variable to String in python | Ploy's Blog | A Blog About Techinical Stuff]</ref> or {{kbd | key=<nowiki>print(type(var))</nowiki>}}
Python type():<ref>[https://docs.python.org/3.6/library/functions.html?highlight=type#type type]</ref><ref>[https://waoewaoe.wordpress.com/2009/05/18/type-cast-variable-to-string-in-python/ Type cast variable to String in python | Ploy's Blog | A Blog About Techinical Stuff]</ref> or {{kbd | key=<nowiki>print(type(var))</nowiki>}}
<pre>
<pre>
Line 22: Line 24:
</pre>
</pre>


=== Javascript ===
Javascript typeof()<ref>[https://www.w3resource.com/javascript/operators/typeof.php JavaScript : typeof operator - w3resource]</ref>
Javascript typeof()<ref>[https://www.w3resource.com/javascript/operators/typeof.php JavaScript : typeof operator - w3resource]</ref>
<pre>
<pre>
Line 32: Line 35:
</pre>
</pre>


=== R ===
R: [https://stat.ethz.ch/R-manual/R-devel/library/base/html/typeof.html typeof()]
R: [https://stat.ethz.ch/R-manual/R-devel/library/base/html/typeof.html typeof()]


== Print the variable ==
== Print the variable ==

Revision as of 10:53, 22 September 2018

Print the type of the variable or just print the variable

Print the type of the variable

PHP

PHP gettype()[1]:

# define the variable
$var = 3.14159;

# print type of the variable
echo "type of variable: " . gettype($var);

Python

Python type():[2][3] or print(type(var))

# define the variable
var = 3.14159

# print type of the variable
type(var) # return <class 'type'>
print(type(var))
print("type of variable: " + str(type(var))) # python v. 3 cast type to string

Javascript

Javascript typeof()[4]

# define the variable
var a = 3.14159;

# print type of the variable
typeof a;
console.log("type of variable:: " + typeof a);

R

R: typeof()

Print the variable

PHP

# define the variable
$var = 3.14159;

echo print_r($var, true) . PHP_EOL;
var_dump($var);

Python

# define the variable
var = 3.14159

print(var)) # python v. 3

References

Related articles


Troubleshooting of ...

Template