Print variable types: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
Print type of the variable
Print type of the variable


* PHP: {{kbd | key=<nowiki>echo "type of variable: " . gettype($var);</nowiki>}}<ref>[http://php.net/manual/en/function.gettype.php PHP: gettype - Manual]</ref>
* PHP gettype(): {{kbd | key=<nowiki>echo "type of variable: " . gettype($var);</nowiki>}}<ref>[http://php.net/manual/en/function.gettype.php PHP: gettype - Manual]</ref>
* Python v. 3:<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>
type(var) # return <class 'type'>
type(var) # return <class 'type'>
print(type(var))
print(type(var))
print("type of variable: " + str(type(var))) # cast type to string
print("type of variable: " + str(type(var))) # python v. 3 cast type to string
</pre>
* Javascript typeof()<ref>[https://www.w3resource.com/javascript/operators/typeof.php JavaScript : typeof operator - w3resource]</ref>
<pre>
typeof var
console.log("type of variable:: " + typeof var)
</pre>
</pre>
* 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()]

Revision as of 15:40, 31 December 2017

Print type of the variable

  • PHP gettype(): echo "type of variable: " . gettype($var);[1]
  • Python type():[2][3] or print(type(var))
type(var) # return <class 'type'>
print(type(var))
print("type of variable: " + str(type(var))) # python v. 3 cast type to string
  • Javascript typeof()[4]
typeof var
console.log("type of variable:: " + typeof var)

references


Troubleshooting of ...

Template