http://dlwt.csdn.net/fd.php?i=858467711513251&s=27caceefbe77d6532f648bb5ae3bc048 这个是Python for MyEclipse的插件
http://dlsw.baidu.com/sw-search-sp/soft/6e/17016/python-3.3.5.1418106245.msi 这个是Python for Windows 安装文件
安装好所需要的文件 。即可在MyEclipse里面开始Python最简单的测试了。
首先选择Python的编译器 在MyEclipse Windows-preferences New
输入名称
选择编译器
**选择所有的 确认OK 等待一下安装
**
完毕之后 就可以开始创建Python工程测试了
选择project
**选择Pydev Project 下一步
**
**选择个语法版本2.5
**
**对工程src -NEW -PyDev Module
**
新建的后缀名为 .py 自动会切换到PyDev perspective 这个视图下可以更好的编辑。
**hello world 代码就一行 比java的少了很多。
**
简单的安装和Python代码运行测试就是这样。很简单。都不需要duang duang duang的。
简单的基础运用代码 可以自己试试一下哦。
2015-03-03 Python 基础知识
'''
@author: 小帅丶
@todo: Python安装使用第一步
Created on 2015-03-03
'''
#coding=utf-8
#Python for String-----------------
str = "HelloWorld"
print (str);#输出字符串内容
print (str[0]);#索引为0的内容
print (str[2:5]);#索引x到y的内容 包头不包尾
print (str *2);#输出2次内容
print (str + "Test");#输出连接的内容
print ('---------------------------------------------');
#Python for List -------------------
list = ['abcd',786,2.23,'john',70.2]
tinylist = [123,'john']
print (list); #输出list
print (list[0]);
print (list[1:3]);
print (list[2:]);#索引2开始 直到最后一个内容输出
print (tinylist*2);
print (list + tinylist);
print ('---------------------------------------------');
#Python for 元组
tuple = ('abcd',786,2.23,'john',70.2)
#tuple[0] = 'zxs' 元组是不可以修改的 List可以
tinytuple = (123,'john')
print (tuple);#输出元组
print (tuple[0]);
print (tuple[1:3]);
print (tuple[2:]);
print (tinytuple*2);
print (tuple + tinytuple);
print ('---------------------------------------------');
#Python 元字典
dict = {}
dict['one'] = "This is one"
dict[2] = "This is two"
tinydict = {'name':'john','code':6734,'dept':'sales'}#key value的关系
print (dict['one']);#输出键为 one的值
print (dict[2]);#输出键为 2的值
print (tinydict);
print (tinydict.keys()); #输出所有的键
print (tinydict.values());#输出所有的值
print ('---------------------------------------------');
2015-03-04 Python 基础知识
'''
Created on 2015-3-4
@author: 小帅丶
'''
#Python for 运算
a = 21
b = 10
c = 0
c = a + b
print ("Line 1 - Value of c is ",c);#加法
c = a - b
print ("Line 2 - Value of c is ",c);#减法
c = a * b
print ("Line 3 - Value of c is ",c);#乘法
c = a / b
print ("Line 4 - Value of c is ",c);#除法
c = a % b
print ("Line 5 - Value of c is ",c);#取余
a = 2
b = 5
c = a**b
print ("Line 6 - Value of c is ",c);#2的5次方
a = 9
b = 2
c = a//b
print ("Line 7 - Value of c is ",c);#取整除
print ("--------------------------");
#Python for 比较运算符
a = 21
b = 10
c = 0
if(a == b):
print ("Line 1 - a is equal to b");
else:
print ("Line 1 - a is not equal to b");
if(a != b):
print ("Line 2 - a is not equal to b");
else:
print ("Line 2 - a is equal to b");
#if(a <> b):
# print ("Line 3 - a is not equal to b");
#else:
# print ("Line 3 - a is equal to b");
if(a < b):
print ("Line 4 - a is less than b");
else:
print ("Line 4 - a is not less than b");
if(a > b):
print ("Line 5 - a is greater than b");
else:
print ("Line 5 - a is not greater than b");
a = 5
b = 20
if(a <= b):
print ("Line 6 - a is either less than b");
else:
print ("Line 6 - a is not neither less than not b");
if(b >= a):
print ("Line 7 - b is either greater than or equal to a");
else:
print ("Line 7 - b is neither greater than nor equal to a");
print ("--------------Pyhton for 赋值运算符-------------------");
#Pyhton for 赋值运算符
a = 21
b = 10
c = 0
c = a + b
print ("Line 1 - Value of c is ",c);
c += a
print ("Line 2 - Value of c is ",c);
c *= a
print ("Line 3 - Value of c is ",c);
c /= a
print ("Line 4 - Value of c is ",c);
c = 2
c %= a
print ("Line 5 - Value of c is ",c);
c **= a
print ("Line 6 - Value of c is ",c);
c //= a
print ("Line 7 - Value of c is ",c);
print ("-------------Python位运算符----------")
#Python for 位运算符
a = 60 #60 = 0011 1100
b = 13 #13 = 0000 1101
c = 0
c = a & b #12 = 0000 1100
print ("Line 1 -Value of c is ",c);
c = a | b #61 = 0011 1101
print ("Line 2 -Value of c is ",c);
c = a ^ b #49 = 0011 0001
print ("Line 3 -Value of c is ",c);
c = ~a # -61= 1100 0011
print ("Line 4 -Value of c is ",c);
c = a << 2 #240 = 1111 0000
print ("Line 5 -Value of c is ",c);
c = a >> 2 #15 = 0000 1111
print ("Line 6 -Value of c is ",c);
print ("----------Python逻辑运算符-----------");
#Python for 逻辑运算符
a = 10
b = 20
c = 0
if(a and b):
print ("Line 1 - a and b are true");
else:
print ("Line 1 - Either a is not true or b is not true");
if(a or b):
print ("Line 2 - Either a is true or b is true or both are true");
else:
print ("Line 2 - Neither a is true nor b is true");
a = 0
if(a and b):
print ("Line 3 - a and b are true");
else:
print ("Line 3 - Either a is not true or b is not true");
if(a or b):
print ("Line 4 - Either a is true or b is true or both are true");
else:
print ("Line 4 - Neither a is true nor b is true");
if not(a and b):
print ("Line 5 - Either a is not true or b is not true or both are not true");
else:
print ("Line 5 - a and b are true");
print ("---------Python成员运算符----------");
a = 10
b = 20
list = [1,2,3,4,5];
if (a in list):
print ("Line 1 - a is available in the given list");
else:
print ("Line 1 - a is not available in the given list");
if(b not in list):
print ("Line 2 - b is not available in the given list");
else:
print ("Line 2 - b is available in the given list");
a = 2
if(a in list):
print ("Line 3 - a is available in the given list");
else:
print ("Line 3 - a is not available in the given list");
print ("---------Python身份运算符--------");
#Python for 身份运算符
a = 20
b = 20
if(a is b):
print ("Line 1 - a and b have same identity");
else:
print ("Line 1 - a and b do not have same identity");
if(id(a)==id(b)):
print ("Line 2 - a and b have same identity");
else:
print ("Line 2 - a and b do not have same identity");
b = 30
if(a is b):
print ("Line 3 - a and b have same identity");
else:
print ("Line 3 - a and b do not have same identity");
if(a is not b):
print ("Line 4 - a and b do not have same identity");
else:
print ("Line 4 - a and b have same identity");
print("-----------Python运算符优先级-----------");
#Python for 运算符优先级
a = 20
b = 10
c = 15
d = 5
e = 0
e = (a + b) * c / d
print ("Value of (a+b)*c/d is",e);
e = ((a + b) * c) / d
print ("Value of ((a+b)*c)/d is", e);
e = (a + b) * (c / d);
print ("Vlaue of (a+b)*(c/d) is", e);
e = a + (b * c) / d;
print ("Value of a + (b * c)/d is ", e);
#2015-03-04代码运行结果
Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of c is 2.1
Line 5 - Value of c is 1
Line 6 - Value of c is 32
Line 7 - Value of c is 4
--------------------------
Line 1 - a is not equal to b
Line 2 - a is not equal to b
Line 4 - a is not less than b
Line 5 - a is greater than b
Line 6 - a is either less than b
Line 7 - b is either greater than or equal to a
--------------Pyhton for 赋值运算符-------------------
Line 1 - Value of c is 31
Line 2 - Value of c is 52
Line 3 - Value of c is 1092
Line 4 - Value of c is 52.0
Line 5 - Value of c is 2
Line 6 - Value of c is 2097152
Line 7 - Value of c is 99864
-------------Python位运算符----------
Line 1 -Value of c is 12
Line 2 -Value of c is 61
Line 3 -Value of c is 49
Line 4 -Value of c is -61
Line 5 -Value of c is 240
Line 6 -Value of c is 15
----------Python逻辑运算符-----------
Line 1 - a and b are true
Line 2 - Either a is true or b is true or both are true
Line 3 - Either a is not true or b is not true
Line 4 - Either a is true or b is true or both are true
Line 5 - Either a is not true or b is not true or both are not true
---------Python成员运算符----------
Line 1 - a is not available in the given list
Line 2 - b is not available in the given list
Line 3 - a is available in the given list
---------Python身份运算符--------
Line 1 - a and b have same identity
Line 2 - a and b have same identity
Line 3 - a and b do not have same identity
Line 4 - a and b do not have same identity
-----------Python运算符优先级-----------
Value of (a+b)*c/d is 90.0
Value of ((a+b)*c)/d is 90.0
Vlaue of (a+b)*(c/d) is 90.0
Value of a + (b * c)/d is 50.0
Python for 数字 2015-03-09
import math
import random
for letter in 'Python':
if letter =='h':
pass
print ('This is pass block');
print ('Current Letter:',letter);
print ('Good bye!');
print("------Random-----");
a = -10
b = 4.1
x = 1
y = 2
print ("值为:",a,"绝对值为:",abs(a));#返回绝对值
print (math.ceil(b));#向上取整
print (math.exp(1));
print (math.fabs(-10));#返回绝对值
print (math.floor(4.9));#向下取整
print (math.log(4,2));#自然数的对数
print (math.log10(100));#基数为10
print (math.pow(2, 2));
print (round(12.334,2));
print (math.sqrt(4));
print ("随机数",random.choice(range(10)));#指定随机数范围
print (random.randrange(100,1000,1));#开始范围 结束范围 递增基数
random.seed(10)
print (random.random());
list = [20,16,10,5];
random.shuffle(list);
print (list);
print (random.uniform(5,10));
print (math.acos(1));
print (math.asin(1));
print (math.atan(1));
print (math.atan2(5, 5));
print (math.cos(3));
print (math.hypot(3, 2));#sqrt(3*3 +2*2)
print (math.sin(3));
print (math.sin(math.pi/2));
print (math.tan(3));
print (math.tan(math.pi/4));
print (math.degrees(2*math.pi));#弧度转为角度
print (math.degrees(math.pi));
print (math.degrees(math.pi/2));
print (math.degrees(math.pi/4));
print (math.radians(0));
print (math.radians(math.pi));
print (math.radians(math.pi/2));
print (math.radians(math.pi/4));
2015-03-10 code for python
var1 = 'Hello World!';
var2 = 'Python Programming';
print (var1[0]);
print (var2[1:5]);
print ('--------------');
#更新字符串
var1 = 'Hello World'
print (var1[:6]+'Python');
print ('--------------');
#List
list1 = [123,'xyz',7899]
list2 = [456,'abc']
print (len(list1));
print (len(list2));
print ('--------------');
#List list()
aTuple = (123,'xyz','zara','abc');
aList = list(aTuple);
print (aList);
print ('--------------');
#List append()
aList = [123,'xyz','zara','abc']
aList.append(2009);
print (aList);
print ('--------------');
#List count
aList = [123,'xyz','zara','abc',123]
print (aList.count(123));
print (aList.count('zara'));
print ('--------------');
#List extend
aList = [123,'xyz','zara','abc',123]
bList = [2009,'manni'];
aList.extend(bList);
print (aList);
print ('--------------');
#List index
aList = [123,'xyz','zara','abc']
print (aList.index('xyz'));
print (aList.index('zara'));
print ('--------------');
#List insert
aList = [123,'xyz','zara','abc']
aList.insert(3, 2009);
print (aList);
print ('--------------');
#List pop
aList = [123,'xyz','zara','abc']
print (aList.pop());
print (aList.pop(2));
print ('--------------');
#List remove
aList = [123,'xyz','zara','abc','xyz']
aList.remove('xyz');
print (aList);
aList.remove('abc');
print (aList);
print ('--------------');
#List reverse()
aList = [123,'xyz','zara','abc','xyz']
aList.reverse();
print (aList);
print ('--------------');
#List sort
aList = [123,'xyz','zara','abc','xyz']
aList.sort();
print (aList);
print ('--------------');