`
sillycat
  • 浏览: 2477431 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

English-009 DiveIntoPython

阅读更多
English-009 DiveIntoPython

1.Note the symmetry here. In this five-element list, li[:3] returns the first 3 elements, and li[3:] returns the last two elements. In fact, li[:n] will always return the first n elements, and li[n:] will return the rest, regardless of the length of the list.
symmetry ['simitri] n. 对称(性);整齐,匀称

2.insert inserts a single element into a list. The numeric argument is the index of the first element that gets bumped out of position. Note that list elements do not need to be unique; there are now two separate elements with the value 'new', li[2] and li[6].
bump [bʌmp]   vt. 碰,撞;颠簸 vi. 碰撞,撞击;颠簸而行

3.index finds the first occurrence of a value in the list and returns the index.
occurrence [ə'kə:rəns, -'kʌ-]   n. 事件;发生;出现;发现

4.If the value is not found in the list, Python raises an exception. This is notably different from most languages, which will return some invalid index. While this may seem annoying, it is a good thing, because it means your program will crash at the source of the problem, rather than later on when you try to use the invalid index.
notable ['nəutəbl]  adj. 值得注意的,显著的;著名的  n. 名人,显要人物
notably  adv. 显著地;尤其
annoying [ə'nɔiiŋ]   adj. 恼人的;讨厌的

5.If the value is not found in the list, Python raises an exception. This mirrors the behavior of the index method.
mirror ['mirə]  vt. 反映;反射

6. A tuple is an immutable list. A tuple can not be changed in any way once it is created.
immutable [i'mju:təbl]  adj. 不变的;不可变的;不能变的

7.A tuple is defined in the same way as a list, except that the whole set of elements is enclosed in parentheses instead of square brackets.
parenthesis [pə'renθisis]  n. 插入语;圆括号;附带 [ 复数parentheses ]
bracket ['brækit]  n. 支架;括号;墙上凸出的托架

8.Tuples can be converted into lists, and vice-versa. The built-in tuple function takes a list and returns a tuple with the same elements, and the list function takes a tuple and returns a list. In effect, tuple freezes a list, and list thaws a tuple.
vice-versa  adv.: 反之亦然  
vice [vais]  n. 缺点;恶习;老虎钳  adj. 代替的;副的
versa adj. 反的
thaw [θɔ:]   vi. 融解;变暖和 vt. 使融解;使变得不拘束

9.Python has local and global variables like most other languages, but it has no explicit variable declarations. Variables spring into existence by being assigned a value, and they are automatically destroyed when they go out of scope.
explicit [ik'splisit] adj. 清楚的;明确的;直率的;详述的
spring [spriŋ]  vi. 跃出;裂开;生长;涌出
existence [iɡ'zistəns]  n. 存在,实在;生存,生活;存在物,实在物

10.Also notice that the variable assignment is one command split over several lines, with a backslash (“\”) serving as  a line-continuation marker.
split [split]  vi. 被劈开;断绝关系;离开
backslash ['bækslæʃ]   n. [计]反斜杠,反斜线符号

11.In C, you would use enum and manually list each constant and its associated value, which seems especially tedious when the values are consecutive. In Python, you can use the built-in range function with multi-variable assignment to quickly assign consecutive values.
associate [ə'səuʃieit, ə'səuʃiət, -eit]   vt. 使发生联系;使联合;联想  associated adj. 关联的;联合的
tedious ['ti:diəs, 'ti:dʒəs]  adj. 冗长乏味的;沉闷的
consecutive [kən'sekjutiv]  adj. 连续不断的;连贯的

12.You might be thinking that this is a lot of work just to do simple string concatentation, and you would be right, except that string formatting isn't just concatenation. It's not even just formatting. It's also type coercion.
concatenation [kɔn,kæti'neiʃən]  n. 串联,连结
coercion [kəu'ə:ʃən]  n. 强迫;强制;高压政治;威压 强制转换;强迫;强制型转;强制

13.In this trivial case, string formatting accomplishes the same result as concatentation.
trivial ['triviəl]  adj. 不重要的,琐碎的;琐细的
accomplish [ə'kʌmpliʃ, ə'kɔm-]  vt. 完成;实现;达到

14.As with printf in C, string formatting in Python is like a Swiss Army knife. There are options galore, and modifier strings to specially format many different types of values.
Swiss [swis] adj. 瑞士的;瑞士人的;瑞士风格的  n. 瑞士人;瑞士腔调
galore [gə'lɔ:,-'lɔə]   a. 丰富的

15.The ".2" modifier of the %f option truncates the value to two decimal places.
truncate ['trʌŋkeit, trʌŋ'keit, 'trʌŋk-] vt. 把…截短;缩短;[物]使成平面

16.You can even combine modifiers. Adding the + modifier displays a plus or minus sign before the value. Note that the ".2" modifier is still in place, and is padding the value to exactly two decimal places.
combine [kəm'bain] vt. 使联合,使结合;使化合

17.One of the most powerful features of Python is the list comprehension, which provides a compact way of mapping a list into another list by applying a function to each of the elements of the list.
comprehension [,kɔmpri'henʃən]  n. 包含;理解
compact [kəm'pækt, 'kɔmpækt]   n. 合同,契约;小粉盒 adj. 紧凑的,紧密的;简洁的

18.Python loops through li one element at a time, temporarily assigning the value of each element to the variable elem. Python then applies the function elem*2 and appends that result to the returned list.
temporarily ['tempərərili, ,tempə'rεə-] adv. 临时地,临时

19.The join method joins the elements of the list into a single string, with each element separated by a semi-colon. The delimiter doesn't need to be a semi-colon; it doesn't even need to be a single character. It can be any string.
semi ['semi]  a.一半的,部分的,不完全的
colon ['kəulən] n 冒号

20.This string is then returned from the odbchelper function and printed by the calling block, which gives you the output that you marveled at when you started reading this chapter.
marvel ['mɑ:vəl] vt. 对…感到惊异 n. 奇迹

21.split reverses join by splitting a string into a multi-element list. Note that the delimiter (“;”) is stripped out completely; it does not appear in any of the elements of the returned list.
reverse [ri'və:s]  vt. 颠倒;倒转
delimiter [di'limitə] n. 定界符
trip [trip]  vi. 绊倒;犯错误;远足;轻快地走

22.When I first learned Python, I expected join to be a method of a list, which would take the delimiter as an argument. Many people feel the same way, and there's a story behind the join method.
Prior to Python 1.6, strings didn't have all these useful methods. There was a separate string module that contained all the string functions; each function took a string as its first argument.
prior ['praiə]  adj. 在先的,在前的;优先的  prior to 在……之前;居先

23.The functions were deemed important enough to put onto the strings themselves, which made sense for functions like lower, upper, and split.
deem [di:m] vt. 认为,视作;相信

24. But many hard-core Python programmers objected to the new join method, arguing that it should be a method of the list instead, or that it shouldn't move at all but simply stay a part of the old string module (which still has a lot of useful stuff in it).
hard-core ['hɑ:dkɔ:]   adj. 中坚的;顽固不化的;赤裸裸描写性行为的 n. 核心成员;铁杆分子

25.I use the new join method exclusively, but you will see code written either way, and if it really bothers you, you can use the old string.join function instead.
exclusive [ik'sklu:siv]  adj. 排外的;独有的;专一的
分享到:
评论

相关推荐

    Dive into python (英文)

    Dive into python, English version

    Test-Driven Development with Python [2017]

    Dive into the TDD workflow, including the unit test/code cycle and refactoring Use unit tests for classes and functions, and functional tests for user interactions within the browser Learn when and ...

    MQTT Essentials - A Lightweight IoT Protocol

    Dive deep into one of IoT's extremely lightweight machines to enable connectivity protocol with some real-world examples Learn to take advantage of the features included in MQTT for IoT and Machine-to...

    Large Scale Machine Learning with Python

    Dive into scalable machine learning and the three forms of scalability. Speed up algorithms that can be used on a desktop computer with tips on parallelization and memory allocation. Get to grips with...

    Python Data Analysis Cookbook

    In this book, you will dive deeper into recipes on spectral analysis, smoothing, and bootstrapping methods. Moving on, you will learn to rank stocks and check market efficiency, then work with metrics...

    Python Deep Learning

    Whether you want to dive deeper into Deep Learning, or want to investigate how to get more out of this powerful technology, you’ll find everything inside. What you will learn Get a practical deep ...

    LargeScaleMachineLearningwithPython.pdf

    Large Scale Machine Learning with Python [PDF + EPUB + CODE] Packt Publishing | August 4, 2016 | English | 439 pages Large Python machine learning projects involve new problems associated with ...

    Hands-On Machine Learning with Scikit-Learn and TensorFlow [EPUB]

    decision trees, random forests, and ensemble methods Use the TensorFlow library to build and train neural nets Dive into neural net architectures, including convolutional nets, recurrent nets, and ...

    Hands-On Machine Learning with Scikit-Learn and TensorFlow [Kindle Edition]

    Dive into neural net architectures, including convolutional nets, recurrent nets, and deep reinforcement learning Learn techniques for training and scaling deep neural nets Apply practical code ...

    Machine.Learning.in.Python

    The chapters on penalized linear regression and ensemble methods dive deep into each of the algorithms, and you can use the sample code in the book to develop your own data analysis solutions. ...

    Machine Learning in Python 无水印pdf 0分

    The chapters on penalized linear regression and ensemble methods dive deep into each of the algorithms, and you can use the sample code in the book to develop your own data analysis solutions....

    Python Machine Learning By Example [2017].azw3电子书下载

    Dive deep into the world of analytics to predict situations correctly Implement machine learning classification and regression algorithms from scratch in Python Be amazed to see the algorithms in ...

    Advanced Analytics with Spark: Patterns for Learning from Data at Scale

    You’ll start with an introduction to Spark and its ecosystem, and then dive into patterns that apply common techniques—including classification, clustering, collaborative filtering, and anomaly ...

    Building Recommendation Engines

    Dive into the various techniques of recommender systems such as collaborative, content-based, and cross-recommendations Create efficient decision-making systems that will ease your work Familiarize ...

    Raspberry Pi Zero Cookbook

    Deep dive into the components of the small yet powerful Raspberry Pi Zero Get into grips with integrating various hardware, programming, and networking concepts with the so-called “cheapest computer...

    Packt.Django.Project.Blueprints.2016

    Dive deep into Django forms and how they work internally About the Author Asad Jibran Ahmed is an experienced programmer who has worked mostly with Django-based web applications for the past 5 years. ...

    React and React Native [Kindle Edition]

    Dive deep into each platform, from routing in React to creating native mobile applications that can run offline Use Facebook's Relay, React and GraphQL technologies, to create a unified architecture ...

Global site tag (gtag.js) - Google Analytics