美文网首页
Python2.7学习笔记:字符串

Python2.7学习笔记:字符串

作者: MarsDream | 来源:发表于2016-10-09 16:13 被阅读0次

    Python字符串基本操作

     ord('A') # ascii code number of A

    cha(65) # ascii code of number 65

    Unicode 介绍:

                 u'\u4e2d' # == u'中文'

    u.'xxx'.encode('utf-8') # transformation of xxx to unicode

    len(u'xxx') # length of unicode string 'xxx'

    为了告知解释器究竟使用哪个解释器和什么编码方式,通常在代码头部加入

    #! /usr/bin/env python

    # -*- coding: utf-8 -*-

    格式化输入输出和C类似,采用占位符方式

    %d整数

    %f浮点数

    %s字符串

    %x十六进制整数

    %% represents %

    Hint: 不知道用啥的时候,记得永远要用%s

    相关文章

      网友评论

          本文标题:Python2.7学习笔记:字符串

          本文链接:https://www.haomeiwen.com/subject/kmapyttx.html