zoukankan      html  css  js  c++  java
  • Python 常用函数

    字符串->数字:

    float(str)

    int(str)

    十六进制字符串转int:

    不带0x前缀:

    x = int('dead',16)

    带0x前缀:

    x = int('0xff', 0)

    其中第二个参数0必须添加,使得开启int根据字符串猜测类型模式

    文件读取:

    readline(line) 一行一行读取,line为指定行

    readlines 将文件每一行作为元素放入一个列表中:

    使用:

    for line in f.readlines():

    read 读取文件所有内容

    查看某一个变量的类型:

    type(var)

    isInstance(var, classinfo)

    classinfo: int, basestring, list, dict, bool

    python问题:

    使用fromkeys(ind,int(ele))报错TypeError: 'int' object is not iterable

    使用sp[ind] = int(ele)就可以了,奇怪的问题

  • 相关阅读:
    hdu 2196(树上点分治)
    hdu 4807(网络流 + 贪心)
    hdu4101
    hdu4216
    hdu 4219, 树形概率DP
    hdu 4127 A*搜索
    hdu 4126
    hdu 5296,15年多校1-7
    poj3436 ACM Computer Factory
    Fence
  • 原文地址:https://www.cnblogs.com/lebronzhang/p/6161060.html
Copyright © 2011-2022 走看看