Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5cde7ea

Browse files
committed
and one line struct and list
1 parentc44329d commit5cde7ea

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

‎if.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
num=randint(1,10);
55
# print num;
66
answer=int(raw_input('输入一个数字: '));
7+
times=0;
78
whileTrue:
9+
times+=1;
810
ifnum==answer:
911
print'猜对啦';
1012
break;
@@ -13,4 +15,8 @@
1315
else:
1416
print'猜小啦';
1517

16-
answer=int(raw_input('输入一个数字: '));
18+
answer=int(raw_input('输入一个数字: '));
19+
20+
# 单行 if
21+
luck= ('好'iftimes<4else'不好');
22+
print'你运气',luck;

‎list.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/python
2+
#coding:utf-8
3+
printdir(list);
4+
arr= [];
5+
arr.append(123);# 追加
6+
arr.append(345);
7+
printarr;#[123, 345]
8+
printlen(arr);#2
9+
arr.pop();# append 的反操作
10+
printarr;#123
11+
arr.pop();
12+
13+
foriinrange(10):
14+
arr.append(i);
15+
16+
# 删除列表中下标为参数的值
17+
arr.pop(3);
18+
arr.pop(0);
19+
printarr;
20+
printarr.index(1);# 0
21+
# print arr.index(19); # 报错。。。
22+
23+
print10*'*','filter map reduce',10*'*';
24+
arr2= [iforiinrange(6)];
25+
arrSum=reduce(lambdax,y:x+y,arr2,0);
26+
printarrSum;
27+
arr2=filter(lambdax:x%2==1,arr2);
28+
printarr2;
29+
arr2=map(lambdax:x*x,arr2);
30+
printarr2;
31+

‎loop.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# range(start, stop[, step])
2-
foriinrange(0,5):
2+
foriinrange(5):
33
printi;
44
print'==============';
55

@@ -9,6 +9,11 @@
99

1010
foriin [0,1,2]:
1111
printi;
12+
13+
# one line loop~ cool~
14+
arr= [-numfornuminrange(20)ifnum%3==1];
15+
printarr;
16+
1217
print10*'*','for end',10*'*';
1318

1419
i=0;

‎module.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@
2222
else:
2323
print'I am being imported from another module'
2424

25-
# 更多关于包的介绍
2625
# http://sebug.net/paper/books/python_hb/node8.html#SECTION008110000000000000000
26+
# 在一个模块被导入时,PVM会在后台从一系列路径中搜索该模块,其搜索过程如下:
27+
# 1、在当前目录下搜索该模块;
28+
# 2、在环境变量PYTHONPATH中指定的路径列表中依次搜索;
29+
# 3、在python安装路径中搜索
30+
# 事实上,PVM通过变量sys.path中包含的路径来搜索,这个变量里面包含的路径列表就是上面提到的这些路径信息

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp