深度学习机器视觉课前基础准备-python数据结构(1)

深度学习机器视觉课前基础准备-python数据结构(1)

数字(Number)
  • Python Number 数据类型用于存储数值,包括整型、长整型、浮点型、复数。

  • Python 中数学运算常用的函数基本都在 math 模块。

    下列几个python种常见的数字处理函数

    返回上入整数

    import math
    ptint(math.ceil(4.1))
    

    输出为:

    5
    

    返回下舍整数

    import math
    print(math.floor(4.1))
    

    输出为

    4
    

    返回数字绝对值

    import math
    print(math.fabs(-10))
    

    输出为

    10.0
    

    返回数字平方根

    import math
    print(math.sqrt(9))
    

    输出为

    3.0
    

    返回e的c次幂

    import math
    print(math.exp(1))
    

    输出为

    2.718281828459045
    
  • Python 中随机数
    随机生成一个[0,1)范围内的实数

    import random
    ran = random.random()
    print(ran)
    

    输出为

    0.12770500612024305
    

    运行多次输出结果不同 (真随机)
    随机生成一个[1,20)范围内的整数

    import random
    ran = random.randint(1,20)
    print(ran)
    

    运行多次输出结果不同 (真随机)
    当用random.seed()设置好种子后,random()生成的随机数就是同一个

    import random
    print("--------设置种子 seed--------")
    random.seed(10)
    ran=random.random()
    print("Random Number with seed 10:",ran)
    

    输出为

    --------设置种子 seed--------
    Random Number with seed 10: 0.5714025946899135
    

    运行多次输出结果相同 (假随机)

    字符串(string)
  • 单引号、双引号、三引号

  • Python中的字符串可以使用单引号 、双引号和三引号(三个单引号或三个双引号)括起来,使用反斜杠 \ 转义特殊字符

    下例方面理解

    print("hello world")
    print('''hello world''')
    

    输出依次为( 故" "与’’’ ‘’'等效)

    hello world
    hello world
    
    print("The \t is Tab")
    print("I\'m going to the movies!")
    

    输出依次为(便于理解转义符 \ 的用途)

    The      is Tab
    I'm going to the movies!
    

    对于第二个输出“I‘m going to the movies!”而言,转义符存在于不存在的输出结果相同。

  • 字符串连接
    下例方便理解
    使用+运算符

    str1="hello "
    str2="world!"
    print(str1+str2)
    

    输出结果为(两字符串+连接是直接暴力相接,中间不会自动加空格或其他东西)

    hello world!
    

    使用join运算符

    new_str = '-'.join("hello")
    print(new_str)
    

    输出结果为

    h-e-l-l-o
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值