zoukankan      html  css  js  c++  java
  • python中的字符数字之间的转换函数

    字符串转数字 / 数字转字符串

    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 )                 将一个整数转换为一个八进制字符串   
     
     
    chr(65)='A'
    ord('A')=65
     
    int('2')=2;
    str(2)='2'
    

      

    其他方式:

    一、字符串转列表的方式

    for循环把字符串 放到 list 中的方式,填空就可以了

    a2 = []
    for _____:
        _____
        a1 = _______
        a2.append(a1)
     
    print a2  
    声明 欢迎转载,但请保留文章原始出处:) 博客园:https://www.cnblogs.com/chenxiaomeng/ 如出现转载未声明 将追究法律责任~谢谢合作
  • 相关阅读:
    LeetCode 485. Max Consecutive Ones
    LeetCode 367. Valid Perfect Square
    LeetCode 375. Guess Number Higher or Lower II
    LeetCode 374. Guess Number Higher or Lower
    LeetCode Word Pattern II
    LeetCode Arranging Coins
    LeetCode 422. Valid Word Square
    Session 共享
    java NIO
    非阻塞IO
  • 原文地址:https://www.cnblogs.com/chenxiaomeng/p/14528353.html
Copyright © 2011-2022 走看看