python中变量pa和pa一样吗_python初级 1 数据类型和变量

一、整数(int)

例:  0 1 2 3 -1 -2 –3

In [31]: print(type(0))

In [32]: print(type(1))

In [33]: print(type(2))

In [34]: print(type(3))

In [35]: print(type(-1))

In [36]: print(type(-2))

In [37]: print(type(-3))

二、浮点数(小数)(float)

例:0.0 0.3  15.5 1.0 –1.45

In [39]: print(type(0.0))

In [40]: print(type(0.3))

In [41]: print(type(15.6))

In [42]: print(type(1.0))

In [43]: print(type(-1.45))

三、字符串(str)

指的是””或是’’里面的内容

例:'2a' "33" "ab\'cd"

In [44]: print(type('2a'))

In [45]: print(type("33"))

In [46]: print(type("ab\'cd"))

In [48]: print("2a")

2a

In [49]: print("33")

33

In [50]: print("ab\'cd")

ab'cd

如果想表示’或是”时,需要采用转义符\, 如果需要表示\时,在外面加上转义符\

例:"I\'m a boy"  "say \"hello world\""  "print \\"

In [51]: print("I\'m a boy")

I'm a boy

In [52]: print("say \"hello world\"")

say "hello world"

In [53]: print("print \\")

print \

四、布尔值(bool)

例:True, False

In [56]: print(type(True))

In [57]: print(type(False))

五、空值(NoneType)

例:None

In [58]: print(type(None))

练习

请打印出以下变量的值:

n = 123

f = 456.789

s1 = 'Hello, world'

s2 = 'Hello, \'Adam\''

s3 = r'Hello, "Bart"'

s4 = r'''Hello, Lisa!'''

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值