【触类旁通】python-基础数据类型

python3的数据类型
请添加图片描述
前端的数据类型
请添加图片描述
java的基本数据类型
请添加图片描述
python例子

a=3
b="nihao"
c=3.3
d=True
e=complex(2,3)
f=(1,2,3)
g=[1,2,3]
h={"key":"value"}
i={1,2,3}
#进行输出
print(type(a))
print(type(b))
print(type(c))
print(type(d))
print(type(e))
print(type(f))
print(type(g))
print(type(h))
print(type(i))
#输出结果
<class 'int'>
<class 'str'>
<class 'float'>
<class 'bool'>
<class 'complex'>
<class 'tuple'>
<class 'list'>
<class 'dict'>
<class 'set'>

前端代码例子

var a = 3 
var b = "hellow"
var c = null
var d = undefined
var e = true
var f = Symbol(2)
var g = {"name":"nihao"}
var h = [1,2,3,4]
var i = function(){}
#不怎么准确的方法,区分不了array和object
console.log(typeof a)
console.log(typeof b)
console.log(typeof c)
console.log(typeof d)
console.log(typeof e)
console.log(typeof f)
console.log(typeof g)
console.log(typeof h)
console.log(typeof i)
结果
number
string
object
undefined
boolean
symbol
object
object
function

#准确的方法
console.log(Object.prototype.toString.call(a))
console.log(Object.prototype.toString.call(b))
console.log(Object.prototype.toString.call(c))
console.log(Object.prototype.toString.call(d))
console.log(Object.prototype.toString.call(e))
console.log(Object.prototype.toString.call(f))
console.log(Object.prototype.toString.call(g))
console.log(Object.prototype.toString.call(h))
console.log(Object.prototype.toString.call(i))
结果
[object Number]
[object String]
[object Null]
[object Undefined]
[object Boolean]
[object Symbol]
[object Object]
[object Array]
[object Function]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李卓书

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值