python脚本编程实例_python⼊门脚本的简单⽰例
编程之家收集整理的这篇⽂章主要介绍了python⼊门脚本的简单⽰例,编程之家⼩编觉得挺不错的,现在分享给⼤家,也给⼤家做个参考。
感兴趣的⼩伙伴,下⾯⼀起跟随编程之家 的⼩编来看看吧。
python代码如下:
#!/usr/bin/python
#Filename: 1.py
i=5
print i
i=i+1
print i
s='welcome to my home!\nI will intorduce my family to you!'
print s,i
length=6
width=5mytatis原理
area=width * length
print 'The Area is',area
print 'The perimeter is',2 * (length + width)
for a in range(2,9):
print a
else:
print 'The loop is over!'
#!/usr/bin/python
#Filename: 3.py
x=raw_input('Enter the value of x: ')
def printMax(x,y)
if a>b:
print x,'is the maximum'
else:
print y,'is the manimum'
printMax(x,y)
#!/usr/bin/python
# Filename: 2.py
b = raw_input('Enter a sentense or words(exit for exit): ')
if b == 'quit' or b == 'exit':
break
elif len(b) < 3:
print 'your input is too short.The length of your input must over3. Please type again!' continue
print 'Ok! The length of your input is over 3,your input is',b
print 'Done!'
[/code]
[code]
database=[
["zhang3","0111"],["li4","0112"],["wang5","0113"]
access下载以及破解]
username=raw_input("what's your user name?")
id=raw_input("what's your id?")
if [username,id] in database: print "access granted"
[/code]
[code]
def bj(x):
if x<0:
print "the number is too small"
elif x>100:
print "the number is too big"
else: print "the number is right!"
x=input("please input a number:")
bj(x)
#读取⽂件的脚本
import os
什么是数据库恢复功能wd()!='/root':
os.chdir('/root')
try:
with open('hi.txt','r') as f:
学python编程入门adline(),end='')
except IOError as err: #此写法仅适⽤于python3
print('File Error:' + str(err))
#!/usr/bin/python
import os
wd()
path2=os.path.abspath('/usr/')
print('使⽤os.getcwd()获取的内容为' + path1)
print('使⽤os.path.abspath()获取的内容为' + path2)
#统计⽂件夹⼤⼩的脚本
import os
from os.path import join,getsize
def getdirsize(dir):
size = 0
for root,dirs,files in os.walk(dir):
size += sum([getsize(join(root,name)) for name in files])
return size
if __name__ == '__main__':
filesize = getdirsize('/tmp')
print ('There are ' + str(filesize/1024/1024) + 'Mbytes in /tmp') #⽂件写⼊的简单脚本
import zipfile
f = zipfile.ZipFile('archive.zip','w',zipfile.ZIP_DEFLATED)
f.write('1.py')
f.write('/root/install.log')
f.close()
#压缩⽂件夹的脚本
#!/usr/bin/python
import zipfile
import os
f = zipfile.ZipFile('archive.zip',zipfile.ZIP_DEFLATED)
startdir = "/root/mydir"
for dirpath,dirnames,filenames in os.walk(startdir):
for filename in filenames:
f.close()
foreign快速记忆#调⽤shell命令的脚本
#!/usr/bin/python
sql语句开发工具
# -*- coding: utf-8 -*-
import os
import commands
statusoutput('pwd')
statusoutput('pwdaa')
print('正确命令的返回状态是: ' + str(a[0]))
print('正确命令的返回结果是: ' + a[1])
print('错误命令的返回状态是: ' + str(b[0]))
print('错误命令的返回结果是: ' + b[1])
c=os.popen('pwd')
ad().rstrip()
# 来⾃
总结
以上是编程之家为你收集整理的python⼊门脚本的简单⽰例全部内容,希望⽂章能够帮你解决python⼊门脚本的简单⽰例所遇到的程序开发问题。
如果觉得编程之家⽹站内容还不错,欢迎将编程之家⽹站推荐给程序员好友。
本图⽂内容来源于⽹友⽹络收集整理提供,作为学习参考使⽤,版权属于原作者。
如您喜欢交流学习经验,点击链接加⼊编程之家官⽅QQ:1065694478
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论