码迷,mamicode.com
首页 > 编程语言 > 详细

Python

时间:2017-11-30 19:11:08      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:python   float   strong   返回结果   add   efi   需要   访问   location   

Python

注释

#Say something NOT IMPORTANT

变量

Python不需要用int, float, doubledefine变量

布尔运算

短路计算。

  1. 在计算 a and b 时,如果 a 是 False,则根据与运算法则,整个结果必定为 False,因此返回 a;如果 a 是 True,则整个计算结果必定取决与 b,因此返回 b。
  2. 在计算 a or b 时,如果 a 是 True,则根据或运算法则,整个计算结果必定为 True,因此返回 a;如果 a 是 False,则整个计算结果必定取决于 b,因此返回 b。

所以,Python解释器在做布尔运算时,只要能提前确定计算结果,它就不会往后算了,直接返回结果。
够懒!!

List

创建List

python classmates = [‘Michael‘, ‘Bob‘, ‘Tracy‘]

List的访问

与数组相同,例如classmate[0] = Michael,此外,List还可以倒序访问,例如classmate[-1] = Tracy

Add

#Say something NOT IMPORTANT
classmate.append("new_classmate")    #Add in the END
classmate.insert(1,"new_classmate")    #Add in the 2nd location

Delete

#Say something NOT IMPORTANT
classmate.opp()    #Delete the FINAL
classmate.insert(1)    #Delete the 2nd

Replace

#Say something NOT IMPORTANT
classmate[0] = 'You'
classmate[-1] = 'Me'

Tuple

tuple一旦创建就不能修改

Create

Like List

classmates = ('Michael', 'Bob', 'Tracy')
className = ('Metoo',)    #Create single element

Variable Tuple

t = ('a', 'b', ['A', 'B'])
L = t[2]
L[0] = 'hha'
L[1] = 'lla'

Python

标签:python   float   strong   返回结果   add   efi   需要   访问   location   

原文地址:http://www.cnblogs.com/pualus/p/7930286.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!