Python学习笔记之数据类型

Python的基本数据类型(标量类型)共有6种。

  1. None
  2. str
  3. bytes
  4. bool True False
  5. int
  6. float

例1 None

None只有一个实例

a = None
print(a is None)

b = 1
print(isinstance(b, int))

例2 长字符串

长字符串三引号开始和结尾内的部分都是字符串内容,包括换行符

a = '''wefwef
this is a long str
include four lines
wefwefewfe'''

b = '''
this is a long str
include four lines
'''

print(a)
print(b.count('\n'))

例3 字符串格式化

template = "{0:s},You are registering,verify code is {1:d}."

msg = template.format('Rhonin', 345672)

print(msg)

表示将第一个参数格式化为字符串,第二个参数格式化为整形。

Leave a Comment

豫ICP备19001387号-1