Python2.7学习笔记:字符串

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容