Python语言概览
python
语言概览
python
脚本可以处理外部传进来的参数 即sys.argv[]
,argv[]
的使用与linux
下相同
python
本身是解释语言,可以对输入的式子求值。python
支持的对象如整数都是立即数,此外他支持复数,及对四则运算解释。
ptyhon
支持字符串,放在单/
双引号内,字符串是数组,可以通过[i:j]
操作获得指定位置(i - j-1)
的元素。多行的字符串可以放在"""
"""
中,如果其中包含了转义字符,r"""\n"""
可以让所有字符都输出。
重载的+ *
操作,可以粘合多个字符串。
python
支持的list
用[a,b,c]
来表示,可以通过[]
取对应的元素,支持多个元素赋值如 a[2:4]=[1,2]
,list
中的元素可以是不同类型的。类似于lisp
,python
中的list
可以嵌套,嵌套的list
作为一个元素。
为了遍历list
可以用for elem in list
:的方式
流程控制
python
中没有{}
,使用缩进来表示代码块,而:表示一块代码的开始,取消缩进表示代码块的结束。
if
x >
0
:
print
1
elif
x==
0
:
print
0
else
:
print
-
1
条件控制
while a>0
in / not in
A and B or (not C)
类定义
class
类名:
类体
函数定义
def fun(argv,argv=x)
:支持默认参数
函数体
如果函数最后的形参为**name
,则函数接收词典。如果函数形参为*name
,则函数接收一个元组或list
。*name
必须在**name
之前。
def
fun
(*argv,**names):
for
arg
in
argv:
print
arg
print
'-'
*
40
keys = names.keys()
for
key
in
keys:
print
key,
":"
,names[key]
fun(
'here are some record'
,liming =
'123456'
,ligang=
'123455'
)
解出参数,
相关文档:
1,下载org.python.pydev.feature-1.5.0.1251989166.zip http://sourceforge.net/projects/pydev/files/
2,安装插件到eclipse
3,重启eclipse
注意:使用1.5.6版本pydev插件,创建python工程会报错,使用1.5.0版本无此问题。 ......
1,编写Server.py
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind(('localhost',8081))
while True:
data,addr=s.recvfrom(1024)
print 'receive:',data,'from',addr
2,编写Client.py
import socket
s=socket.socket(socket.AF_INET,socket.SOC ......
python的变参
*args和**dargs是Python的两个可
变参数,两者有所不同的是*args是个tuple,**dargs是个dict。
*args
和**dargs并用时,*args必须放在**dargs的前面。
例如:
def func(a,b, *c):
pass
函数func至少有两个参数变参数放在tuple c中
def func(*c): 或者 def func(**d ......
#from pp3e Chapter 9.3
#############################################################################
# popup three new window, with style
# destroy() kills one window, quit() kills all windows and app; top-level
# windows have title, icon, iconify/deiconify and protocol for wm events;
# there ......
list.append(item)
list.extend(sequence)
http://docs.python.org/tutorial/datastructures.html
http://docs.python.org/library/functions.html 这几天看一下
python howto
恩。python documentation 确实很好很强大啊!
list.append(x)Add an item to the end of the list; equivalent to a[len(a):]&n ......