pyhotn3入门基础-2数据类型和变量

1.字符串

>>> print('I\'m ok.')
I'm ok.
>>> print('I\'m learning\nPython.')
I'm learning
Python.
>>> print('\\\n\\')
\
\

#转义
>>> print('\\\t\\')
\       \
>>> print(r'\\\t\\')
\\\t\\

#打印多行
>>> print('''line1
... line2
... line3''')
line1
line2
line3

2. 布尔值

   True 和 False 

>>> True
True
>>> False
False
>>> 3 > 2
True
>>> 3 > 5
False
  布尔值可以用and or not 运算
>>> True or True
True
>>> True or False
True
>>> False or False
False
>>> 5 > 3 or 1 > 3
True
>>> not True
False
>>> not False
True
>>> not 1 > 2
True

if age >= 18:
    print('adult')
else:
    print('teenager')

3. 空值

  None

4. 变量

a = 123 # a是整数
print(a)
a = 'ABC' # a变为字符串
print(a)

a = 'ABC'
b = a
a = 'XYZ'
print(b)

ABC

5. 除法

   / 除法结果是浮点数    // 除法结果是整数

>>> 10 / 3
3.3333333333333335
>>> 9 / 3
3.0
>>> 10 // 3
3




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值