易截截图软件、单文件、免安装、纯绿色、仅160KB

python语法介绍

1.1. 语法
1.1.1. if
>>> x=int(raw_input("please enter an integer:"))
please enter an integer:-8
>>> if x<0:
...  print 'negative'
... elif x==0:
...  print 'zero'
... else:
...  print 'positive'
...
negative
这里有几个知识点需要提醒:
1。和shell中if语句的区别
我们来回顾一下shell中的if语句。
shell中if语句的结构是:
if 表达式
then 命令表
[else]
fi
举个简单的例子:ifsingle
#!/bin/bash
#filename:ifsingle
echo "please enter the first string:"
read word1
echo "please enter the second string:"
read word2
echo "_______________"
if test $word1 = $word2 这里注意$word1和$word2之间的等号前后必须有空格,不然就变成了赋值语句,程序的功能就体现不出来了。
 then
 echo " the first string is equal to the second string"
fi
echo "the program has finished"
并且if语句可以无限层的嵌套在其他if语句中。
python中的是一个if,elif,else语句实现多路判断
我们同样举一个相似的例子:
使用vi编辑器进行编辑:
#!/bin/bash
#filename:ifelif
echo "please enter the first argu:"
read str1                            z注意这里切不要使用$1,因为$1是指除了程序名的第一个参数
echo "please enter the second argu:"
read str2
echo "please enter the third argu:"
read str3
if test $str1 = $str2 -a $str2 = $str3 test 用[ ]是test的语法,需要用-a表示逻辑与,当然test 也可以不实用[]
 then
 echo "the three argu are same"
 elif test $str1 = $str2
 then
  echo "the first argu is equal to the second argu"
 elif test $str2 = $str3
 then
  echo "the second argu is equal to the third argu"
 elif test $str1 = $str3
 then
  echo "the third argu is equal to the first argu"
else
echo " they are different"
fi
2


相关文档:

python实现twitter client

公司的代理可以直接穿墙,自由访问Twitter、Facebook等网站,这两天研究了一下Twitter提供的API,用python写了一个twitter client,只实现了基本功能,查看自己的twitter消息,也可以不验证,查看public的twitter消息。其他功能实现类似。主要函数如下:
def fetch_with_proxy(proxy, username, password, url):
 &n ......

python 之 pil生成验证码图片

#!/usr/bin/python
#coding=utf-8
import Image,ImageDraw,ImageFont,os,string,random,ImageFilter
def initChars():
"""
允许的字符集合,初始集合为数字、大小写字母
usage: initChars()
param: None
return: list
返回允许的字符集和
for: picChecker类初始字符集合
todo: ......

选择阅读Python源码来进一步提高算法

最近在研读Python源码剖析一书,此书相当不错,如果自己冲动的去分析Python源码可能会到处碰“鼻”,看到此书时是09年,那时为了研究内存机制才发现有这么一本书,但是工作太忙,根本没时间去分析源码,到了2010年,这是非常有深重意义的一年,所以这一年一定要比之前做的还要付出更多,要想成为技术顶尖就必须研 ......

Python中执行shell命令的实例

1。
myCoolVariable="some_string"
os.system("echo myCoolVariable")
2.
>>> os.system('echo "asdg"')
asdg
0
>>> os.system("echo 'asdgwere'")
asdgwere
0
3.
$ python
>>>hamburger="potato"
>>>import os
>>>os.system("echo 'hamburger'")
potato
0
......

windows下使用gcc调用python的问题

用gcc编译了一个C++调用python的程序,这个程序在VS下是好用的,而且没有使用vs的任何库
可是到了gcc下就是无法使用
后来上网查了一下资料才知道,是因为cl与gcc的运行时库不同。
打开cmd窗口,输入python就可以看到
Python 3.0 (r30:67507, Dec  3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32
Type " ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号