#Assign a value
number =50#Check the is more than 50 or notif(number >=50):print("You have passed")else:print("You have not passed")
3. 转换图片格式JPEG
import os
import sys
from PIL import Image
iflen(sys.argv)>1:if os.path.exists(sys.argv[1]):
im = Image.open(sys.argv[1])
target_name = sys.argv[1]+".jpg"
rgb_im = im.convert('RGB')
rgb_im.save(target_name)print("Saved as "+ target_name)else:print(sys.argv[1]+" not found")else:print("Usage: convert2jpg.py <file>")
4. 在系统里寻找文件
import fnmatch
import os
rootPath ='/'
pattern ='*.mp3'for root, dirs, files in os.walk(rootPath):for filename in fnmatch.filter(files, pattern):print( os.path.join(root, filename))
5. 随机密码生成器
import string
from random import *
characters = string.ascii_letters + string.punctuation + string.digits
password ="".join(choice(characters)for x in range(randint(8,16)))print(password)
6. 数一数列表中的字母有几个
#Define thestring
string ='Python Bash Java PHP PHP PERL'#Define thesearch string
search ='P'#Store the count value
count = string.count(search)#Print the formatted outputprint("%s appears %d times"%(search, count))