python学习(1)--基础知识

万物皆对象。


在Pyhon中一切都是对象,并且几乎一切都有属性和方法。


一切都可以赋值给变量

或者

作为参数传递给函数。


http://www.python.org/doc/current/ref/

(http://www.python.org/doc/current/ref/objects.html

(http://www.effbot.org/guides/

(http://www.effbot.org/guides/python-objects.htm


--------------------------------------------------------------------------------------------------------------------------------

测试模块

模块式对象,有__name__属性。

当import此模块时,__name__就是模块的名字,没有后缀之类的。

当像一个标准的程序一样去运行这个模块时,__name__就是缺省值__main__。

这样就提供了一个机制,利用这个特点做测试。

if __name__ == "__main__":
	myParams = {"server":"mpilgrim", \
				"database":"master", \
				"uid":"sa", \
				"pwd":"secret"
				}
	print buildConnectionString(myParams)

>>> import odbchelper
>>> odbchelper.__name__
'odbchelper'


Python Reference Manual (http://www.python.org/doc/current/ref/) 讨论了导入模块 的底层细节。

 (http://www.python.org/doc/current/ref/import.html)

-----------------------------------------------------------------------------------------------------

语句和语句块分割

Python 使用硬回车来分割语句,冒号和缩进来分割代码块。

Python Reference Manual (http://www.python.org/doc/current/ref/) 讨论讨论了交叉缩进问题,并且演示各种样的错误, (http://www.python.org/doc/current/ref/indentation.html)。
·Python Style Guide (http://www.python.org/doc/essays/styleguide.html) 讨论了良好的缩进风格。

-------------------------------------------------------------------------------------------------------------









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值