安装索引
在vim编辑器中安装配置实现在编辑器中检验脚本的运行状况
1.vim编辑器的配置文件为:/etc/vimrc
通过:sudo vim /etc/vimrc 打开vim的配置文件
在结尾添加如下内容即可指定F5为测试脚本的快捷键:
注:此方式便于对脚本进行单元测试。
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'java'
exec "!javac %"
exec "!time java %<"
elseif &filetype == 'sh'
:!time bash %
elseif &filetype == 'python'
exec "!time python2.7 %"
exec "!time python3.6 %"
elseif &filetype == 'html'
exec "!firefox % &"
elseif &filetype == 'go'
exec "!go build %<"
exec "!time go run %"
elseif &filetype == 'mkd'
exec "!~/.vim/markdown.pl % > %.html &"
exec "!firefox %.html &"
endif
endfunc
示例
vim testF5.py
在编辑python时,当有中文输出或注释时,出现错误提示:SyntaxError: Non-ASCII character ‘\xe7’ in file …
在当前的.py文件的开头写上:
#-- coding:UTF-8 -- 或者 #coding=UTF-8 (必须在首行添加,否则无法执行)
x=input("请输入数字:")#基本输入为字串形态
x=int(x)#转换为整数形态
if x>200:
print("大于200")
elif x>100:
print("大于100,小于200");
else:
print("小于100");
执行直接按F5
Press ENTER or type command to continue
请输入数字:120
大于100,小于200
real 0m9.273s
user 0m0.007s
sys 0m0.001s
返回直接按Tab返回,输入集合,F5执行
集合
交集和并集-符号 &和 |
差集和反交集-符号 -和^
S1={3,4,5}
S2={4,5,6}
S3=S1&S2
Press ENTER or type command to continue
set([4, 5])
S1={3,4,5}
S2={4,5,6}
S3=S1|S2
print(S3)
结果:Press ENTER or type command to continue
set([3, 4, 5, 6])
S1={3,4,5}
S2={4,5,6}
S3=S1-S2
结果:Press ENTER or type command to continue
set([3])
S1={3,4,5}
S2={4,5,6}
S3=S1^S2
结果:Press ENTER or type command to continue
set([3, 6])
判断集合 in 或 not in
S1={3,4,5}
S2={4,5,6,7}
S3=S1&S2
print(S3)
结果:Press ENTER or type command to continue
set([4, 5])
S1={3,4,5}
print(6 in S1)
结果:Press ENTER or type command to continue
False
S1={3,4,5}
print(6 in S1)
结果:Press ENTER or type command to continue
False
S1={3,4,5}
print(6 not in S1)
结果:Press ENTER or type command to continue
True
字典 键值对(Key-Value)
判断键值对用 in 和 not in 删除用 delete
dic={x:x*2 for x in [3,4,5]}
print(dic)
结果:Press ENTER or type command to continue
{3: 6, 4: 8, 5: 10}
四则运算
n1=int(input("请输入数字一:"))
n2=int(input("请输入数字二:"))
print(n1+n2)#可以用加减乘除的符号(+、-、*、/)
Press ENTER or type command to continue
请输入数字一:1
请输入数字二:1
2a=1
b=2
c=3
ans=(a+b+c)/3
print(ans)
if 判断
chinese = 56
english = 46
math = 100
if chinese == 100 and english == 100 and math == 100:
print("Pass");
else:
print("Fail")
结果:Press ENTER or type command to continue
Fail
chinese = 56
english = 46
math = 100
if chinese == 100 or english == 100 or math == 100:
print("Pass");
else:
print("Faile");
结果:Press ENTER or type command to continue
Pass
累加
i=0
i=i+1;
i=i+1
print(i);
结果:Press ENTER or type command to continue
2
for 循环
for i in range(0,2):
print("Hello")
结果:
Press ENTER or type command to continue
Hello
Hello
while 循环
i=0;
while(i<10):
print("Hello")
i+=1;
结果:Hello
程式
def f(x):
return x+3
def f(x):
return x+3
print(f(2))
结果:Press ENTER or type command to continue
5