Chinaunix首页 | 论坛 | 博客
  • 博客访问: 26267000
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类: Python/Ruby

2008-11-12 14:35:02

1.print "%s is number %d!"%("python",1)
可以像C中的printf格式 一样哦得到的结果为:python is number 1!
2.通过help()函数是可以得到一个函数的帮助信息出来。
help(raw_input)
Help on built-in function raw_input in module __builtin__:

raw_input(...)
    raw_input([prompt]) -> string
   
    Read a string from standard input.  The trailing newline is stripped.
    If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
    On Unix, GNU readline is used if enabled.  The prompt string, if given,
    is printed without a trailing newline before reading.
3.来讲一下PYTHON中的数字类型吧
五种数字类型:
int(有符号整数) long(长整数) bool(布尔类型) float(浮点类型) complex(复数)
其中long 相当于我们的java中的bigInteger类型。
4.来分析一下字符串类型
支持使用成对的单引号或双引号,三引号可以用来包含其特有的索引规则:第一个字符的索引是0最后一个字符的索引是-1
+用户字符串连接运算,*字符串重复。
>>> pystr='Python'
>>> iscool='is cool!'
>>> pystr[0]
'P'
>>> pystr[2:5]
'tho'
表示2>>> pystr*2
'PythonPython'  #表示字符串重复
>>> pystr[:2]
'Py'            #表示从开始到第二个位置
5.列表和元组
相当于JAVA中的数组,能够保存任意数量类型的python对象。也是从0开始的数字索引访问元素,但是能够保存不同类型的对象。
通过切片运算([]和[:])可以得到子集。这一点与字符串的使用方法是一样的。
aList = [1,2,3,4]
>>> aList
[1, 2, 3, 4]
>>> aList[0]      #相当于JAVA中的数组吧!
1
>>> aList[2:]
[3, 4]
元组研究:
aTuple=('robots',77,93,'try')
>>> aTuple
('robots', 77, 93, 'try')
>>> aTuple[:3]
('robots', 77, 93)
>>> aTuple[1]
77
2.9字典
相当于哈希表一样的。由键-值对构成的。一般以数字或字符串为常用。
字典元素用{}包裹起来的!
>>> aDict['names']
'zhoujl'
>>> aDict={'names':'zhoujl'}
>>> aDict['sex']='boy'
>>> aDict
{'names': 'zhoujl', 'sex': 'boy'}
>>> aDict.keys()
['names', 'sex']
>>> aDict['names']
'zhoujl'
其实发现字典这种数据类型很不错的。能够通过名字来提取出来对应的数值出来的!
这样很方便去提取出来相关的数值出来!
2.10 代码块及缩进对齐





阅读(700) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~