Code First 代码为先,通过运行代码来学习一门新的语言,个人的学习习惯,首先来看几个处理数字的例子
-
>>>2+2
-
4
-
>>>(50+5*7)/4
-
21.25
-
>>>8/5
-
1.6000000000000001
-
>>>print(8/5)
-
1.6
-
>>>8//5
-
1
- >>>
说明:两个数字相除,从结果上看,应该默认是浮点,//表示整除
下面是复数的运算,很简单
-
>>>4*complex(1,7)
-
(4+28j)
-
>>>(1+2j)/(1+1j)
-
(1.5+0.5j)
-
>>>a=3+4j
- >>>a.real
-
3.0
- >>>a.imag
-
4.0
- >>>abs(a)
-
5.0
- >>>
下面看一个例子
-
>>>tax=12.5/100
-
>>>price=100.5
- >>>price*tax
-
12.5625
- >>>price+_
-
113.0625
-
>>>round(_,3)
-
113.062
- >>>
说明:_ 表示上一次的运算结果,round 为什么不是 113.063呢?感觉比较奇怪
下面看一下String的例子
-
>>>str='does\'t'
-
>>>print(str)
- does't
-
>>>str="\"Yes\"hesaid."
-
>>>print(str)
-
"Yes"hesaid.
-
>>>word="Word"+'A'
-
>>>'<'+word+'>'
-
'<WordA>'
-
>>>'<'+word*3+'>'
-
'<WordAWordAWordA>'
-
>>>word[1:4]
-
'ord'
-
>>>word[1:]
-
'ordA'
- >>>len(word)
-
5
- >>>
比较惊奇,字符串可以做乘法
下面看看List的例子
-
>>>a=['spam','eggs',100,1234]
- >>>a
-
['spam','eggs',100,1234]
-
>>>a[0]
-
'spam'
-
>>>a[-1]
-
1234
-
>>>a[1:-1]
-
['eggs',100]
-
>>>a[2]=a[2]+23
- >>>a
-
['spam','eggs',123,1234]
-
>>>a[0:2]=[1,12]
- >>>a
-
[1,12,123,1234]
-
>>>a[0:2]=[]
- >>>a
-
[123,1234]
-
>>>a[1:1]=['bletch','xyzzy']
- >>>a
-
[123,'bletch','xyzzy',1234]
-
>>>a[:0]=a
- >>>a
-
[123,'bletch','xyzzy',1234,123,'bletch','xyzzy',1234]
- >>>len(a)
-
8
- >>>
和其他语言不同的是下标,从左到右是0到n-1 从右到左是-1 到-n
最后来一个有点意义的例子斐波纳契数列f(n)=f(n-1)+f(n-2) ,n>=2,f(0)=0,f(1)=1
-
>>>f0,f1=0,1
-
>>>whilef1<1000:
-
...print(f1,end="")
- ...f0,f1=f1,f1+f0
- ...
-
1123581321345589144233377610987>>>
分享到:
相关推荐
Python Continuous Integration and Delivery: A Concise Guide with Examples By 作者: Moritz Lenz ISBN-10 书号: 1484242807 ISBN-13 书号: 9781484242803 Edition 版本: 1st ed. 出版日期: 2018-12-29 pages ...
这本书《Probability: Theory and Examples》是由Rick ...《Probability: Theory and Examples》这本书不仅适合概率论的研究者和专业人士阅读参考,也是概率论入门者学习概率基础理论和深入理解概率思想的宝贵资料。
Companion Software for Digitale Signalverarbeitung: Grundlagen und Anwendungen Beispiele und Ubungen mit MATLAB (Digital Signal Processing: Fundamentals and ... Examples and Exercises with MATLAB)
Quickly learn how to automate unit testing of Python 3 code with Python 3 automation libraries, such as doctest, unittest, nose, nose2, and pytest. This book explores the important concepts in ...
Probability: Theory and Examples,by Durrent,概率论专业经典教材。答案很少见,特意贡献~~~ 教材电子版已更新至第四版,可以在Durrent‘s homepage下载~!
读书笔记:Programming In Scala 3rd Examples.《Scala编程》第三版代码
这是完全版本的英文书,共747页,182M,txt文件中是百度云的链接地址,如果失效请留言并发站内消息
and diagnosing medical diseases, the list goes on and on. If you want to become a machine learning practitioner, a better problem solver, or maybe even consider a career in machine learning research, ...
2. **新增章节**:增加了关于多维布朗运动及其与偏微分方程关系的新章节,并且在第七章中加入了伊藤公式(Itô's formula)的证明,为新章节的引入奠定了基础。 3. **布朗运动章节重构**:原有的布朗运动章节被拆分...
概率论非常经典的书籍,包括大数定律、中心极限定理、随机游动、鞅、马尔可夫链、遍历定理和布朗运动。它是一种综合性的处理方法,...它的哲学是,学习概率的最好方法是看到它的实际行动,所以有200个例子和450个问题。
It starts with a review of some core Python principles, which are illustrated by various concepts and examples later in the book. The first half of the book explores aspects of functions, classes, ...
Title: Python for Data Analysis: Data Wrangling with Pandas, NumPy, and IPython, 2nd Edition Author: Wes McKinney Length: 550 pages Edition: 2 Language: English Publisher: O'Reilly Media Publication D...
algorithm design foundations analysis and internet examples 中文版
越来越多的企业,如快手、美团、百度等,都在使用Python进行各种技术应用,这也为学习Python的求职者提供了丰富的就业机会。 首先,Python全栈工程师是Python领域的核心角色之一。他们能够运用Python的语法基础,...
world examples ranging from individual snippets to 40 large scripts and full implementation case studies, you’ll use the interactive IPython interpreter with code in Jupyter Notebooks to quickly ...
**网页抓取基础与最佳实践:Python在数据科学中的应用** 网页抓取,或称网络爬虫,是一种从互联网上自动提取大量数据的技术。在数据科学领域,它扮演着至关重要的角色,因为许多有价值的信息都隐藏在网页的HTML代码...
标题《[Durrett] Probability Theory and Examples Solutions.pdf》和描述“概率论”指明了文档内容与概率论领域紧密相关,特别是《概率论与例题解答》一书的第二版中解决方案的详细讨论。这本书的第二版增加了解决...