zoukankan      html  css  js  c++  java
  • 数据类型转换

    1.常用的数据类型转换

    函数说明
    int(x [,base ]) 将x转换为一个整数
    long(x [,base ]) 将x转换为一个长整数
    float(x ) 将x转换到一个浮点数
    complex(real [,imag ]) 创建一个复数
    str(x ) 将对象 x 转换为字符串
    repr(x ) 将对象 x 转换为表达式字符串
    eval(str ) 用来计算在字符串中的有效Python表达式,并返回一个对象
    tuple(s ) 将序列 s 转换为一个元组
    list(s ) 将序列 s 转换为一个列表
    chr(x ) 将一个整数转换为一个字符
    unichr(x ) 将一个整数转换为Unicode字符
    ord(x ) 将一个字符转换为它的整数值
    hex(x ) 将一个整数转换为一个十六进制字符串
    oct(x ) 将一个整数转换为一个八进制字符串

    2. 进制转换

    <1>不同进制的书写方式

    • 八进制(Octal) 0o377
    • 十六进制(Hex) 0xFF
    • 二进制(Binary) 0b11111111

    <2>不同进制之间的转换

    python提供了三个内置的函数,可以用来在不同进制间做转换

    print (oct(255))
    print (hex(255))
    print (bin(255))
    

    运行结果:

    0o377

    0xff

    0b11111111

    还可以使用int函数,把字符串转成数值

    print (int('255'))
    print (int('0xFF', 16))
    

     运行结果:

    255

    255

  • 相关阅读:
    Spring boot mybatis : Error creating bean with name 'com.github.pagehelper.autoconfigure.MapperAutoConfiguration': Invocation of init method failed;
    方法调用
    初识MQ
    Shell 变量
    Eclipse 导入本地 Git 项目
    IDEA 常用快捷键
    Xshell 配色方案
    冒泡排序
    递归
    安卓服务Service详解
  • 原文地址:https://www.cnblogs.com/loaderman/p/6559852.html
Copyright © 2011-2022 走看看