命名规则和基本数据类型

一.数据类型

1.介绍了几种基本的数据类型:

1. 引用了type()方法查看变量的数据类型
  • str 字符串类型

    a = "wall eye knee"
    print(type(a)) #<class 'str'>
    
    c = "666"
    print(type(c)) #<class 'str'>
    
    
  • int型

    b = 666
    print(type(b)) #<class 'int'>
    
  • float 型

    d = 123.456
    print(type(d)) #<class 'float'>
    

    *complex型

    #  复数  实部+虚部j
    #  虚数不单独存在,跟着实数一起
    test = 100 + 20j
    print(test.real)  # 100.0 获取实部
    print(test.imag)  # 20.0  获取虚部
    
  • bool 型

    e = True
    print(type(e)) #<class 'bool'>
    
  • list 列表

    f = [1, a, b, c, d, e]
    print(type(f))  #<class 'list>
    
  • tuple 元组

    g = (1, 2, 3)
    print(type(g)) #<class 'tuple'>
    
  • dict 字典 格式: {keys : value}

    h = {"name": "Alice", "age": "18"}
    print(type(h)) #<class 'dict'>
    
  • set 集合

    i = {1, 2, 3}
    print(type(i)) #<class 'set'>
    

注意:函数也是一种数据类型

二.标识符的命名

1.命名规则

  • 标识符由字母、下划线、和数字组成,且数字不能开头

  • 不能以关键字命名

    # print = 123
    # print(print) # 会报错'int' object is not callable
    
    # int = 666
    # print(int) # 不会报错,但是最好不要使用关键字
    
  • 区分大小写

    Name = "a"
    name = "b"
    print(name, Name)  # 输出结果:b a3.格式化输出
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值