Python (一)
来源:互联网 发布:暗影格斗2mac版存档 编辑:程序博客网 时间:2024/04/28 21:33
为什么使用Python?
http://reliscore.com/blog/why-every-programmer-should-learn-python-or-ruby/ 给出了为什么每个程序员都要学习Python,并且各种当前主要语言进行对比。
下载python:
http://www.python.org/官网上下载。
安装Python:
在Windows下有exe自动安装 。在linux中可能需要手动安装推荐博文:http://www.cnblogs.com/yuechaotian/archive/2013/06/03/3115482.html
第一个Python程序:
经典的Hello World:
>>> print 'Hello World'Hello World在输出字符串的时候需要使用单引号或者双括号,稍后介绍print函数。
内部数据类型:
在python中定义一个变量时不需要声明函数类型:
>>> l = True>>> type(l)<type 'bool'>>>> l = 's'>>> type(l)<type 'str'>>>> l = 1>>> type(l)<type 'int'>
字典(Dictionary):Python中的字典类型酷似Java中的HashTable类的实例。
字典类型中 使用Key-Value 关系模型
>>> dic = {1:'a',2:'b',3:'c',4:'d'}>>> type(dic)<type 'dict'>
查看关于字典类型的方法:
在Python中万物皆对象。 这里使用dir() 内部函数:
>>> type(dic)<type 'dict'>>>> dir(dic)['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values', 'viewitems', 'viewkeys', 'viewvalues']方法介绍:
keys方法:返回字典类型所有的keys
>>> dic.keys()[1, 2, 3, 4]
- (一)python初探
- Python学习(一)
- Python学习 (一)
- Python学习(一)
- Python基础知识(一)
- Python基础知识(一)
- python学习(一)
- python学习(一)
- Python集锦(一)
- Python学习(一)
- python学习(一)
- Python 基础(一)
- python学习(一)
- python学习(一)
- python笔记(一)
- Python (一)
- python理论学习(一)
- Python进阶(一)
- 我的CSDN 账户为zhousiwei锁住了
- NSNotificationCenter通知接收多次
- 微信公众帐号开发教程第5篇-各种消息的接收与响应
- Android回调机制的讨论
- sql语法:inner join on, left join on, right join on详细使用方法
- Python (一)
- Linux/CentOS 读写windows下的NTFS硬盘
- SurfaceView与多线程的混搭
- Oracle常用函数
- 《斯大林格勒》公映 重新定义战争与和平
- Oracle数据库like查询
- 微信公众帐号开发教程第6篇-文本消息的内容长度限制揭秘
- 用for语句求1000以内所有偶数的和
- 求奖金总数