易截截图软件、单文件、免安装、纯绿色、仅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 ......

我的VIM配置(ubuntu+python)

1,不用修改/etc/vim下的vimrc及gvimrc文件 。。。
      2,在~目录下,新建一个.vimrc的配置文件。内容如下:(高亮,自动对齐,自动缩进,显示行号)
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last change: 2006 Nov ......

【Python】用Python来实现凑24的程序

凑24是经典的益智游戏,多玩可以使脑筋灵活一点,但是当遇到无解的时候,就会很伤脑筋,为此,写个程序来代为计算。
运行结果,去除了重复的一些表达式:
entry: 1
entry: 4
entry: 5
entry: 6
(4/(1-(5/6))) = 24
(6/((5/4)-1)) = 24
Press any key to exit...
entry: 3
entry: 3
entry: 8
entry: 8
(8/(3-(8 ......

python random 随机的问题

在一个项目中需要获取随机数,谁知道遇到点问题:随机数不随机。所以我写了个简单原型。看下到底是啥问题。
import os,random,sys,time
while True:
father = os.fork()
if father:
time.sleep(2)
rd = 7
else:
#random.seed()
rd = random.choice([2,3,4,5])
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号