Python基礎(chǔ)(草稿)

#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

傳參數(shù)

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) #縮進即關(guān)系

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()? ? 轉(zhuǎn)成數(shù)字

break

continue

def gree()

print

def gree(arg1='aaa')

print

while aaa:

print

def gree(*arg)

print

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()

print

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 幫助關(guān)閉文件

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)? 轉(zhuǎn)時間格式

set()

aa[0:3]

class Aa(object):

def __init__(self):

class Nextlist(list):

dict()? 空字典

#######################################

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末魁淳,一起剝皮案震驚了整個濱河市具帮,隨后出現(xiàn)的幾起案子囱桨,更是在濱河造成了極大的恐慌斑司,老刑警劉巖绽媒,帶你破解...
    沈念sama閱讀 218,284評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件妙蔗,死亡現(xiàn)場離奇詭異傲霸,居然都是意外死亡,警方通過查閱死者的電腦和手機眉反,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,115評論 3 395
  • 文/潘曉璐 我一進店門昙啄,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人寸五,你說我怎么就攤上這事梳凛。” “怎么了梳杏?”我有些...
    開封第一講書人閱讀 164,614評論 0 354
  • 文/不壞的土叔 我叫張陵韧拒,是天一觀的道長。 經(jīng)常有香客問我十性,道長叛溢,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,671評論 1 293
  • 正文 為了忘掉前任劲适,我火速辦了婚禮楷掉,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘霞势。我一直安慰自己烹植,他們只是感情好斑鸦,可當我...
    茶點故事閱讀 67,699評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著草雕,像睡著了一般巷屿。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上墩虹,一...
    開封第一講書人閱讀 51,562評論 1 305
  • 那天嘱巾,我揣著相機與錄音,去河邊找鬼败晴。 笑死浓冒,一個胖子當著我的面吹牛栽渴,可吹牛的內(nèi)容都是我干的尖坤。 我是一名探鬼主播,決...
    沈念sama閱讀 40,309評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼闲擦,長吁一口氣:“原來是場噩夢啊……” “哼慢味!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起墅冷,我...
    開封第一講書人閱讀 39,223評論 0 276
  • 序言:老撾萬榮一對情侶失蹤纯路,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后寞忿,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體驰唬,經(jīng)...
    沈念sama閱讀 45,668評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,859評論 3 336
  • 正文 我和宋清朗相戀三年腔彰,在試婚紗的時候發(fā)現(xiàn)自己被綠了叫编。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,981評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡霹抛,死狀恐怖搓逾,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情杯拐,我是刑警寧澤霞篡,帶...
    沈念sama閱讀 35,705評論 5 347
  • 正文 年R本政府宣布,位于F島的核電站端逼,受9級特大地震影響朗兵,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜顶滩,卻給世界環(huán)境...
    茶點故事閱讀 41,310評論 3 330
  • 文/蒙蒙 一余掖、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧诲祸,春花似錦浊吏、人聲如沸而昨。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,904評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽歌憨。三九已至,卻和暖如春墩衙,著一層夾襖步出監(jiān)牢的瞬間务嫡,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,023評論 1 270
  • 我被黑心中介騙來泰國打工漆改, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留心铃,地道東北人。 一個月前我還...
    沈念sama閱讀 48,146評論 3 370
  • 正文 我出身青樓挫剑,卻偏偏與公主長得像去扣,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子樊破,可洞房花燭夜當晚...
    茶點故事閱讀 44,933評論 2 355

推薦閱讀更多精彩內(nèi)容