Python2.7学习笔记:字符串

2016-10-09  本文已影响0人  MarsDream

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

上一篇 下一篇

猜你喜欢

热点阅读