• Welcome to Rotar E@rth!
  • Feel free to look around and comment~
  • Tin - for a better fantasy life!
  • TinTimer - for an even better fantasy life!

Python 笔记01| Notes about Python 01

Mobile phone Rotar 13年前 (2010-12-02) 2488次浏览 4个评论

近几日花了挺多时间在这上面,效果也较为显著,PMangar基本被实现了。期间有一些心得在这儿写下来做记录,顺便也分享:
I’ve been working on Python these days and here are some notes for it:

  1. Python中不支持在string.find(str)中使用正则表达式,即str只能是string。
    str in string.find(str) can not be a regular expression, it should be a string.
    Code:
    [python]
    a=’abcd0123.py’
    a.find(“[w]*.py”)
    a.find(“0123.py”)

    #Result:
    #-1
    #4
    [/python]

  2. 使用for i in range(a,b)时,i的值可以等于a到不b-1而不会等于b。同理对于i[a:b]会截取i的第a至b-1个元素。
    In Python, any operation involving a range of a to b means the value can be from a to b-1.
    Code:
    [python]
    for i in range(0,2)
    print i
    a=”0123456789″
    print a[3:7]

    #Result:
    #0
    #1
    #3456
    [/python]

  3. 当已知一个字符的Unicode编码时,例如a=”u4eba”,可以通过unichr()和int()将其转换为相应字符的Unicode形式即b=”u4eba”
    When you know the unicode number of a charactor, you can get the corresponding character by using unichr() and int().
    Code:
    [python]
    a=r’u4eba’ #a is a string with 6 characters, the last 4 characters represents the unicode number of a chinese character “人”.
    b=int(a[2:7],16) #Converting string to an decimal integer using base 16
    c=unichr(int) #Find the corresponding unicode charactor of the number
    print a
    print b
    print c

    #Result:
    #u4eba
    #20154 #<--This is the decimal number for hex num '4eba' #人 [/python]


本网站采用BY-NC-SA协议进行授权 , 转载请注明原文链接:Python 笔记01| Notes about Python 01
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(4)个小伙伴在吐槽
  1. 你是学计算机嗒? 那些是编程么?好难好复杂啊...你都能背下来?
    小雪=3=2011-04-08 01:48 Reply 未知操作系统 | 未知浏览器
    • 是编程的……不过只是兴趣爱好,专业是电子工程OTL
      Rotar2011-06-22 01:45 Reply 未知操作系统 | 未知浏览器
  2. @ @.....晕头.....不懂...
    雪の嗳嗳ぺ2011-01-01 04:13 Reply 未知操作系统 | 未知浏览器
    • 俺看Spanish也是……@_@晕头不懂
      Rotar2011-01-02 17:37 Reply 未知操作系统 | 未知浏览器