简明python教程 单词解析.docx
《简明python教程 单词解析.docx》由会员分享,可在线阅读,更多相关《简明python教程 单词解析.docx(16页珍藏版)》请在冰豆网上搜索。
简明python教程单词解析
radius半径(圆的半径)
temperature温度
shapeless不定期的
false错误的
——————————————————
Traceback(mostrecentcalllast):
File"",line1,in
NameError:
name'a'isnotdefined
——————————————————
python提示错误数
—traceback回溯(su)
错误消息与追溯
追踪
追溯
----------trace追踪back返回
—mostrecentcalllast
most大部分;大多数;最为
recent近期以来,最近,近况
call调用
last持续;历时;
------------------------------------
continues连续的
---------------------------------
value重要的
---------------------------------
member成员
-------------------------------
Indentation[ɪnden'teɪʃ(ə)n]缩进Error['erə]错误:
unexpected
[ʌnɪk'spektɪd;]意料之外;意想不到indent[ɪn'dent]缩进
意想不到的缩进
--------------------------------
SyntaxError语法错误:
invalid[ɪn'vælɪd]无效syntax['sɪntæks]语法
-----------------------------------------
#!
/usr/bin/python最大的目录/二进制/python
#Filename:
expression.py
expression[ɪk'spreʃ(ə)n;ek-]表达式
length[leŋθ]长度
breadth[bredθ;-t-]宽度;幅度
area['eərɪə]面积
perimeter[pə'rɪmɪtə]周长,边界
parameter[pə'ræmɪtə]参数
--
控制流——ifforwhile
-------------------
guess(盖哎私)猜测
Enteraninteger:
(输入一个整数)
Enter输入;进入;回车键
an一个
integer整数
------------------
Congratulations.youguessedit('恭喜你你猜对了!
')
————Congratulation[kən,grætʃə'leʃənz]恭喜,祝贺;
————guessed猜测
————it它
----------------
Newblockstartshere('新的块从这里开始')
——New新的,新鲜的
——block[blɒk]块
——starts—start的复数开始,起始
——here[hɪə]这里
--------------
butyoudonotwinanyprizes(扑入哎私)但是你没有获得任何奖励!
——but但是,不过,可是
——you你
——do做,干
——not不,不是
——win获胜,赢得
——any[enɪ]任何,什么,一些
——prizes—prize复数奖励,奖品,奖项
-------------
Nesblock(不唠嗑)endshere新的块在这里结束
——ends结束
-------------
if(判断,如果)elif(否则如果,或者如果)else(或者)
--------------
No,itisalittlehigher(孩儿)thanthat不,它比你输入的那个数更大。
——No,不
——itisa,它是一个
——little英['lɪt(ə)l]美['lɪtl]小,少,小小,极少,鲜有
——higher英[ˈhaɪə(r)]高于
——than比较,超过
——that那个
-------------
Anotherblock另一个块
——Another美[ə'nʌðɚ](俺拿点...)另一个,另外一个
------------
Youcandowhateveryouwantinablock你可以做任何你想要的在一块
——Youcando
——whatever美[wət'ɛvɚ]无论什么;诸如此类
______adj.adjective形容词
______pron.代词
______conj.[kən'dʒʌŋ(k)ʃ(ə)n]连接词
----------
No,itisalitterlowerthanthat它是一个与它相比更小的数
——lower[loɚ]减少,降低
youmusthaveaguess>numbertoreachhere
你必须有一个数大于number,才能到达这里。
-------------
Done[dʌn]完成了,(做,do的过去分词)
--------------------------
Thislaststatementisalwaysexecuted,aftertheifstatementisexecuted
最后这句话总是在执行if语句后才执行
——last英[lɑːst]末尾;最后,最后的;
——statement英['steɪtm(ə)nt]声明;陈述,叙述;报表,清单
——always['ɔlwez],永远,一直,总是,常常
——execute—executed['ɛksɪ,kjʊt]实行;执行;处死
——after后来,以后;在...之后
--------------------------------
——range范围,幅度
——
----------------------------------
while..else..只要..不然..
Entersomething点儿..随便输入些什么吧
——quit退出
——break打破;中断
——len字符串长度,长度
——continue继续,连续,下去
——print打印
-------------------------------------
Inputisofsufficientlength输入足够的长度
——input输入,投入,输入框
——sufficient[sə'fɪʃ(ə)nt]足够的,充分的
——length[leŋθ]长度,衣长
--------------------------------------
Dootherkindsofprocessinghere做其他类型的处理吗
——other其他的,另外的
——Kinds—kind种类
——process扑入啊塞斯or普若塞斯进程;过程;流程;加工
——here[hɪə]这里
-----------------------------------
#!
/usr/bin/python
#Filename:
function1.py
defsayHello():
print'HelloWorld!
'#blockbelongingtothefunction
sayHello()#callthefunction
def定义函数
——定义defined
——function['fʌŋ(k)ʃ(ə)n]函数
definedfunction——def
——say说,说出
——Hello你好
blockbelongingtothefunction这一块属于这个函数"sayHello"
——block块,这一片区域,
——belong属于,应归入;——belonging所有物,附属物
callthefunction调用这个函数
-----------------------------------------
#!
/usr/bin/python
#Filename:
func_param.py
defprintMax(a,b):
ifa>b:
printa,'ismaximum'
else:
printb,'ismaximum'
printMax(3,4)#directlygiveliteralvalues直接给文字值
x=5
y=7
printMax(x,y)#givevariablesasarguments
——param—parametric[pærə'metrɪk]参数;参量
——maximum['mæksɪməm]最大的;最多的
——directly[dɪ'rektlɪ;daɪ-]直接,立即;马上;正好
——give给,产生,面向,
——literal逐字的,文字的
——value['væljuː]外遨游——values值;价值;价格;重要性;确切涵义
------givevariablesasarguments给变量作为参数
——variables变量
——as因为;随着;虽然;依照;当…时
——argument['ɑːgjʊm(ə)nt]内容提要
-------------------------------------
deffunc(x):
print'xis',x
x=2
print'changedlocalxto',x
x=50
func(x)
print'xisstill',x
——local本地setlocalenabledelayedexpansion设置本地启用延迟扩展
——change[tʃeɪn(d)ʒ]改变,变化
——still[stɪl]尽管如此,仍然
---------------------------
global['gləʊb(ə)l]全球的;总体的;球形的
-----------------------------------------
#!
/usr/bin/python
#Filename:
func_default.py
defsay(message,times=1):
printmessage*times
say('Hello')
say('World',5)
default——默认的,系统的参数
——message[mesɪdʒ]信息,通知
——times使…相乘;乘以
——say[seɪ]讲,说明,表示
----------------------------------
return[rɪ'tɜːn]回程的;返回的
---------------------------------
document['dɒkjʊm(ə)nt]文件,文档
string字符串
DocStrings文档字符串
defprintMax(x,y):
'''Printsthemaximumoftwonumbers.
Thetwovaluesmustbeintegers.'''
x=int(x)#converttointegers,ifpossible
y=int(y)
ifx>y:
printx,'ismaximum'
else:
printy,'ismaximum'
------------------------
——convert[kən'vɜːt]转换,改变
——possible['pɒsɪb(ə)l]可能,可能性,合适
——----------------------
import进口、输入
if__name__=='__main__':
print'Thisprogramisbeingrunbyitself'
else:
print'Iambeingimportedfromanothermodule'
-------
——name名字,命名
——main[meɪn]主要的,主要部分
_Thisprogramisbeingrunbyitself这个程序通过它本身运行
——program程序,计划
——being[bɪŋ]堆,材料堆
——run运转,运行
——by通过,经过
——itself[ɪt'self]它自己,它本身
_Iambeingimportedfromanothermodule我从另一个模块导入
——module['mɒdjuːl]模块;组件;模数
-----------------------------------------------------
#Filename:
mymodule.py
defsayhi():
print'Hi,thisismymodulespeaking.'
version='0.1'
#Endofmymodule.py
——mymodule我的模块
——speak—speaking[spiːk]说话,讲话,发言
——version['vɜːʃ(ə)n]版本
——demo['deməʊ]演示,样本
$python
>>>importsys
>>>dir(sys)#getlistofattributesforsysmodule
['__displayhook__','__doc__','__excepthook__','__name__','__stderr__',
'__stdin__','__stdout__','_getframe','api_version','argv',
'builtin_module_names','byteorder','call_tracing','callstats',
'copyright','displayhook','exc_clear','exc_info','exc_type',
'excepthook','exec_prefix','executable','exit','getcheckinterval',
'getdefaultencoding','getdlopenflags','getfilesystemencoding',
'getrecursionlimit','getrefcount','hexversion','maxint','maxunicode',
'meta_path','modules','path','path_hooks','path_importer_cache',
'platform','prefix','ps1','ps2','setcheckinterval','setdlopenflags',
'setprofile','setrecursionlimit','settrace','stderr','stdin','stdout',
'version','version_info','warnoptions']
>>>dir()#getlistofattributesforcurrentmodule
['__builtins__','__doc__','__name__','sys']
>>>
>>>a=5#createanewvariable'a'
>>>dir()
['__builtins__','__doc__','__name__','a','sys']
>>>
>>>dela#delete/removeaname
>>>
>>>dir()
['__builtins__','__doc__','__name__','sys']
>>>
-------------------------
dir(sys)getlistofattributesforsysmodule获得系统模块的属性列表
——get[get]使得;获得;受到;变成
——list[lɪst]列表;清单;目录
——attributes属性
——sys系统文件
——module['mɒdjuːl]module模块
------
getlistofattributesforcurrentmodule得到当前模块的属性列表
——current['kʌr(ə)nt]现在的,流通的,最近的
——module模块
-----------------
createanewvariable'a'创建一个新的变量"a"
——create[kriː'eɪt]创造,创建
——variable变量。
可变的,易变的
-----------------
delete/removeaname删除一个名称
——delete[dɪ'liːt]删除
——remove移动,开除,调动
----------------------------
Helponclassintinmoduleint类模块的帮助
——append[ə'pend]附加;贴上设置数据文件的搜索路径
——field[fiːld]领域,战场
-----------------------------
#!
/usr/bin/python
#Filename:
using_list.py
#Thisismyshoppinglist
shoplist=['apple','mango','carrot','banana']
print'Ihave',len(shoplist),'itemstopurchase.'
print'Theseitemsare:
',#Noticethecommaatendoftheline注意这个逗
号在最后
foriteminshoplist:
printitem,
——mango['mæŋgəʊ]芒果
——carrot['kærət]胡萝卜
——banana[bə'nɑːnə]香蕉
——item['aɪtəm]条款,商品,物品
——purchase['pɜ:
tʃəs]购买,采购,购入
——these[ðiːz]这些,这些个,此等
——notice['nəʊtɪs]通知,公告,注意,商品描述
——comma['kɒmə]逗号,逗点标点符号中点号的一种
————foriteminshoplist从这个商品列表中读取条目
foriteminshoplist
-----------------------------------------------
print'\nIalsohavetobuyrice.'我还要买大米
shoplist.append('rice')
print'Myshoppinglistisnow',shoplist——现在我的购物清单
print'Iwillsortmylistnow'我现在将我的列表排序
shoplist.sort()
print'Sortedshoppinglistis',shoplist——排序的购物清单是
print'ThefirstitemIwillbuyis',shoplist[0]——我首先要买的是
olditem=shoplist[0]
delshoplist[0]
print'Iboughtthe',olditem
print'Myshoppinglistisnow',shoplist——我现在的购物清单是
——also['ɔlso]而且,并且,另外
——buy[baɪ]购买,采购
——rice[raɪs]大米
——will将;愿意;必须
——sorted分类的,分选的
——first第一首先优先
——old旧的,古老的olditem旧的物品
——bought[bɔːt]buy的过去式和过去分词表示已经买过的物品
---------------------------------------------------------------------------------
-------------------
#!
/usr/bin/python
#Filename:
using_list.py
#Thisismyshopinglist
shoplist=['apple','mango','carrot','banana']
print'Ihave',len(shoplist),'itemstopurchase.'
print'Theseitemsare:
',#Noticethecommaatendiftheline
foriteminshoplist:
printitem,
print'\nIalsohavetobuyrice.'
shoplist.append('rice')
print'Myshoppinglistisnow',shoplist
print'Iwillsortmylistnow'
shoplist.sort()
print'Sortedshoppinglistis',shoplist
print'ThefirstitemIwillbuyis',shoplist[0]
olditem=shoplist[0]
delshoplist[0]
print'Iboughtthe',olditem
print'Myshoppinglistisnow',shoplist
raw_input('wait..')
---------------------------------------------------------------------------------
-----------------------
$pythonusin