python核心编程第二版附录a

python核心编程第二版附录a

ID:5347869

大小:336.13 KB

页数:10页

时间:2017-12-08

python核心编程第二版附录a_第1页
python核心编程第二版附录a_第2页
python核心编程第二版附录a_第3页
python核心编程第二版附录a_第4页
python核心编程第二版附录a_第5页
资源描述:

《python核心编程第二版附录a》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、Chun_AppA.fmPage1011Wednesday,August23,20065:19PMAnswerstoSelectedExercisesChapter25.Loopsandnumbersa)i=0whilei<11:i+=1b)foriinrange(11):pass6.Conditionalsn=int(raw_input('enteranumber:'))ifn<0:print'negative'elifn>0:print'positive'else:print'zero'1011Chun_AppA.fmPage1012Wednesday,August23,2006

2、5:19PM1012AppendixA7.Loopsandstringss=raw_input('enterastring:')foreachCharins:printeachChar#(doesnotprintindex)orforiinrange(len(s)):printi,s[i]ori=0slen=len(s)whilei

3、)printsubtotor#usessum()BIFandgeneratorexpressionsprintsum(int(raw_input('enteranumber:'))foriinrange(5))Chapter34.StatementsUse;5.StatementsUse(unlesspartofacomma-separatedsequenceinwhichcaseisoptional)7.Identifiers40XLnumber$saving$symbolprintkeyword0x40Lnumberbig-daddysymbol2hot2touchnumber

4、thisIsn'tAVarsymbolifkeywordcounter-1symbolChun_AppA.fmPage1013Wednesday,August23,20065:19PMAnswerstoSelectedExercises1013Chapter41.PythonobjectsAllPythonobjectshavethreeattributes:type,ID,andvalue.Allareread-onlywithapossibleexceptionofthevalue(whichcanbechangedonlyiftheobjectismutable).5.str(

5、)vs.repr()repr()isabuilt-infunctionwhilestr()wasabuilt-infunctionthatchangedtoafactoryfunctioninPython2.2.Theywillbothreturnastringrep-resentationofanobject;however,str()returnsaprintablestringrepresenta-tionwhilerepr()(andthebackquoteoperator‘‘)returnanevaluatablestringrepresentationofanobject

6、,meaningthatitisastringthatrepresentsa(valid)Pythonobjectthatwouldbecreatedifpassedtoeval().6.Objectequalitytype(a)==type(b)whetherthevalueoftype(a)isthesameasthevalueoftype(b)...==isavaluecomparetype(a)istype(b)whetherthetypeobjectsreturnedbytype(a)andtype(b)arethesameobjectSincethereexistsonl

7、yone(type)objectforeachbuilt-intype,thereisnoneedtochecktheirvalues;hence,onlythelatterformshouldbeused.Chapter58.Geometryimportmathdefsqcube():s=float(raw_input('enterlengthofoneside:'))print'theareais:',s**2.,'(unitssquared)'pri

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。