① 如何使用python运行文件
使用python运行文件的方法:
1、打开运行栏的方法使用win+r组合快捷键。在运行栏中输入cmd打开命令行窗口。
2、在命令提示符窗口中首先进入py命令所在的文件夹。本例中使用的py命令位于e盘根目录下。dos命令中切换根目录直接输入驱动器盘符即可。
3、直接键入python xx.py后回车确认。得到正确的运行结果。本例是个最简单的hello,world!的程序,运行后在命令行窗口中显示该串字符。
相关学习推荐:python教程
② Python怎么return后让循环继续运行
return 会直接另函数返回,函数就运行结束了,所有该函数体内的代码都不再执行了,所以该函数体内的循环也不可能再继续运行。
如果你需要让循环继续执行,就不能return函数,而应该选用break或者continue。
break:跳出所在的当前整个循环,到外层代码继续执行。
continue:跳出本次循环,从下一个迭代继续运行循环,内层循环执行完毕,外层代码继续运行。
return:直接返回函数,所有该函数体内的代码(包括循环体)都不会再执行。
用下边的示例代码来解释:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def return_continue_break(type):
if(not type in ["return", "continue", "break"]):
print '"type" should be "return, continue, break".'
return
for j in range(0, 10):
for i in range(0, 10):
print "j_i: %d_%d" %(j, i)
if(i > 3):
if(type == "return"):
return
elif(type == "continue"):
continue
else:
break
print "executed!"
if __name__ == '__main__':
return_continue_break("break")
return_continue_break("continue")
return_continue_break("return")
BREAK的输出为:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
j_i: 0_0
executed!
j_i: 0_1
executed!
j_i: 0_2
executed!
j_i: 0_3
executed!
j_i: 0_4
j_i: 1_0
executed!
j_i: 1_1
executed!
j_i: 1_2
executed!
j_i: 1_3
executed!
j_i: 1_4
j_i: 2_0
executed!
j_i: 2_1
executed!
j_i: 2_2
executed!
j_i: 2_3
executed!
j_i: 2_4
j_i: 3_0
executed!
j_i: 3_1
executed!
j_i: 3_2
executed!
j_i: 3_3
executed!
j_i: 3_4
j_i: 4_0
executed!
j_i: 4_1
executed!
j_i: 4_2
executed!
j_i: 4_3
executed!
j_i: 4_4
j_i: 5_0
executed!
j_i: 5_1
executed!
j_i: 5_2
executed!
j_i: 5_3
executed!
j_i: 5_4
j_i: 6_0
executed!
j_i: 6_1
executed!
j_i: 6_2
executed!
j_i: 6_3
executed!
j_i: 6_4
j_i: 7_0
executed!
j_i: 7_1
executed!
j_i: 7_2
executed!
j_i: 7_3
executed!
j_i: 7_4
j_i: 8_0
executed!
j_i: 8_1
executed!
j_i: 8_2
executed!
j_i: 8_3
executed!
j_i: 8_4
j_i: 9_0
executed!
j_i: 9_1
executed!
j_i: 9_2
executed!
j_i: 9_3
executed!
j_i: 9_4
RETURN的输出为:
1
2
3
4
5
6
7
8
9
j_i: 0_0
executed!
j_i: 0_1
executed!
j_i: 0_2
executed!
j_i: 0_3
executed!
j_i: 0_4
CONTINUE的输出为:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
j_i: 0_0
executed!
j_i: 0_1
executed!
j_i: 0_2
executed!
j_i: 0_3
executed!
j_i: 0_4
j_i: 0_5
j_i: 0_6
j_i: 0_7
j_i: 0_8
j_i: 0_9
j_i: 1_0
executed!
j_i: 1_1
executed!
j_i: 1_2
executed!
j_i: 1_3
executed!
j_i: 1_4
j_i: 1_5
j_i: 1_6
j_i: 1_7
j_i: 1_8
j_i: 1_9
j_i: 2_0
executed!
j_i: 2_1
executed!
j_i: 2_2
executed!
j_i: 2_3
executed!
j_i: 2_4
j_i: 2_5
j_i: 2_6
j_i: 2_7
j_i: 2_8
j_i: 2_9
j_i: 3_0
executed!
j_i: 3_1
executed!
j_i: 3_2
executed!
j_i: 3_3
executed!
j_i: 3_4
j_i: 3_5
j_i: 3_6
j_i: 3_7
j_i: 3_8
j_i: 3_9
j_i: 4_0
executed!
j_i: 4_1
executed!
j_i: 4_2
executed!
j_i: 4_3
executed!
j_i: 4_4
j_i: 4_5
j_i: 4_6
j_i: 4_7
j_i: 4_8
j_i: 4_9
j_i: 5_0
executed!
j_i: 5_1
executed!
j_i: 5_2
executed!
j_i: 5_3
executed!
j_i: 5_4
j_i: 5_5
j_i: 5_6
j_i: 5_7
j_i: 5_8
j_i: 5_9
j_i: 6_0
executed!
j_i: 6_1
executed!
j_i: 6_2
executed!
j_i: 6_3
executed!
j_i: 6_4
j_i: 6_5
j_i: 6_6
j_i: 6_7
j_i: 6_8
j_i: 6_9
j_i: 7_0
executed!
j_i: 7_1
executed!
j_i: 7_2
executed!
j_i: 7_3
executed!
j_i: 7_4
j_i: 7_5
j_i: 7_6
j_i: 7_7
j_i: 7_8
j_i: 7_9
j_i: 8_0
executed!
j_i: 8_1
executed!
j_i: 8_2
executed!
j_i: 8_3
executed!
j_i: 8_4
j_i: 8_5
j_i: 8_6
j_i: 8_7
j_i: 8_8
j_i: 8_9
j_i: 9_0
executed!
j_i: 9_1
executed!
j_i: 9_2
executed!
j_i: 9_3
executed!
j_i: 9_4
j_i: 9_5
j_i: 9_6
j_i: 9_7
j_i: 9_8
j_i: 9_9
③ 怎么让一个python脚本双击直接运行
linux系统里面,在命令行下面执行下面命令.
chmod +x test.py
这样test.py脚本就有了"可执行"的属性,在GUI里面就能双击运行了.
windows系统里面,如果你已经安装了python,那么直接双击,脚本是会运行的.不过有可能你直接看不到结果.
④ python程序运行结束后,怎么让它自动回到开头重新运行
1、首先在电脑的搜索框中输入“idle”,出现的“IDLE”就是Python的入口,如下图所示。
⑤ python代码怎么运行
一、使用Python的解释器:
1、安装python一般都会有一个交互式解释器,我们可以在这里直接写入运行
2、但如果我们将其关闭,刚才写的代码就会丢失。此时,我们新建一个文本文档,写入print 'hello world',然后将文件名改写为:hello.py。注意,后缀名是py,你的电脑要显示后缀名才可以看见。然后,我们打开解释器,通过file->open打开刚才写的py
3、打开后会显示如下界面,就是我们刚才写的代码
4、此时,可以点击Run->run mole,或者直接按F5,运行代码,如下图所示,运行成功,并打印结果
二、通过命令行运行
如下图所示,有一个hello.py的文件
我们直接在上面的文件地址栏输入cmd,敲入回车
可以看到,直接就定位到对应的目录下
我们输入python hello.py,可以运行程序
也可以直接运行hello.py
三、双击运行:
可以直接双击运行,但是这样窗口会一闪而过,怎么办呢?
加入如下代码:
raw_input('press <enter>')
此时,我们再直接双击程序,发现cmd框并没有消失,此时你按下回车键,界面才会消失
更多Python相关技术文章,请访问Python教程栏目进行学习!
以上就是python怎么运行代码程序的详细内容,
⑥ 怎样用python在代码运行完重复运行
前面加一个while函数
可以用while
True
也可以设置一个问题例如输入’开始’进行,输入’退出’结束
希望对你有帮助
⑦ 在python编辑器里编好程序以后接着怎样运行
你一定是在解释器运行的吧。。把代码写到脚本就可以了。。你右键打开idie的时候
会同时打开解释器和脚本的是吧。。python
shell
是解释器
那个自然就是脚本了
⑧ Python编辑器里面怎么让指令一下子运行完
在IDLE里先新建一个脚本,然后输入全部代码,最后点击run,就能把你脚本里面全部的代码运行一遍。
⑨ python这个怎么运行
哪个?
如果是代码的话,保存到一个文件中,命名成xxx.py,然后执行: pythonl xxx.py 即可
linux文件第一行加上 #!/usr/bin/env python 再给这个文件加上执行权限就可以直接运行
如果你问python本身的话,直接敲python会车就行了,进入python的交互命令行
⑩ python3怎样让第一个程序运行完后再运行第二个程序
你说的第1第2 程序是python写的还是别的语言写的?
如果是python写的,直接在python3里import然后依次执行即可