#python ex1.py
##
# -- coding:utf-8 --
print “Hello World!”
print 6+2
print "aa","bb"
print "%s %d %i "%(aa,bb,cc)
print "%d"%10
print x
print y
$r False True
string+string
print aa,bb 逗号即空格
print "."*10
formater="%r %r %r %r"
print formater%(1,2,3,4)
%r everything
\n 换行
"""
xx
yy
xx
yy
""" #三个引号代表多行
获取用户输入 raw_input()
raw_input("how old are you")
pydoc raw_input
传参数
from sys import argv
script,first,second,third=argv #脚本名字,变量1,2,3
a=open(filename)
a.read()
from sys import argv
script,filename=argv
file=open(filename)
file.read()
file.readline()
file.truncate()
file.seek(0)
file.write("sss")
file.close()
from sys import argv
from os.path import exists
script,ffile,tfile=argv
input=open(ffile)
indata=input.read()
len(indata) ##len
exists(tfile) ##exists
output.write(indata)
output.close()
input.close()
def funt(a1,a2)
print "%r %r"%(a1,a2)
return 1
funt(1,2)
string.split(' ')
string.pop(0)
if xx:
print xx
if xx:
elif xx:
else:
xx
the_count=[1,2,3,4,5]
for nu in the_count:
print nu
for i in range(1,5)
num=[]
num.append(i)
a=num[1]
字典 del
from random import randint
randint(0,5)
class Employee(Person):
def __init__(self,a,b):
#######pip distribute nose virtualenv
try:
except :
string.upper()
string.lower()
string.title() 首字母大写
string.strip()
string.rstrip()
string.lstrip()
str(23)
sss=[]
sss.append()
sss.insert(0,'aa')
del sss[0]
sss.pop() delete the last
sss.pop(0)
sss.remove('aa')
sss.sort()
sss.sort(reverse=True) 永久性排序
sorted(sss) 临时排序
sss.reverse()
sss[-1] 最后一个元素
for a in sss:
print(a) #缩进即关系
for a in range(1,7):
print(a)
sss=list(range(1,8))
sss=list(range(2,11,2))
min(sss)
max(sss)
sum(sss)
sss[0:3]
sss[0:]
aaa=sss[:]
sss=(111,2222) #不可更改
for i in range(1,5):
if i<=3:
print(i)
else:
print(i)
aaa={1:333,2:3333}
aaa[1]
del
for key,value in aaa.items():
for a in aaa.keys():
sorted(aaa.keys())
aaa.values()
set(aaa.values()) 不重复的值
raw_input()
int() 转成数字
break
continue
def gree()
def gree(arg1='aaa')
while aaa:
def gree(*arg)
from modulename import fun1,fun2,fun3
import pp as p
p.fun2()
from modulename import *
#################################################################
class Dog(object):
def __init__(self,name,age)
def sit(self)
class Dog(Cat):
def __init__(self):
super(Dog,self).__init__()
from Dog import Dog
from Dog import Dog,Cat
import Dog as hh
hh.cc()
from Dog import *
######################################################################
with open('a.txt') as fi:
fi.read()
readline()
with open('a.txt','w') as fi:
fi.write('aa\n')
with open('a.txt','a') as fi:
fi.write('aa')
try:
xx
except xx:
pass
import json
json.dump()
json.load()
####################################################################
aa.append
aa.insert
for a in aa:
print(a)
aa[0][1][3]
isinstance(aa,list)
##
for each_item in movies:
if isinstance(each_item,list):
for ne in each_item:
print(ne)
else:
print(each_item)
##
list()
range
enumerate
int
id
next()
#######
pypi
#####
thefile=open('xx.txt')
thefile.close()
import os
os.getcwd()
os.chdir('')
os.getcwd()
data=open()
data.seek(0)
data.close()
(a,b)=string.split(':')
print(a)
print(b)
string.find(':')
if string.find(':')==-1
xx
try:
except:
pass
file.open
file.readline
file.close
file.find
string.strip
string.lstrip
string.rstrip
out=open('xx.txt','w')
print("xxx",file=out)
out.close()
try:
except:
finally:
try:
with open('xx.txt','w') as data:
print('sss',file=data)
except:
print('error')
with 帮助关闭文件
sys.stdout
sys.stdint
#####################
###二进制读写文件
import pickle
with open('xx.pickle','wb') as aa:
pickle.dump('xxx',aa)
with open('xx.pickle','rb') as bb:
ali=pickle.load(bb)
locals() 返回当前作用域的变量集合
##################
data.sort()
sorted(data)
secs=[m*60 for m in mins]
sanitize(t) 转时间格式
set()
aa[0:3]
class Aa(object):
def __init__(self):
class Nextlist(list):
dict() 空字典
#######################################