- #!/usr/local/bin/python3
- #coding=UTF-8
- '''''
- Created on 2011-2-25
- @author: Jacky
- '''
- import sys
- #逻辑与运算符and:x and y 如果x为false则返回x,如果x为true则返回y
- #False
- print("false and true:",False and True)
- #False
- print("true and false:",True and False)
- #True
- print("true and true:",True and True)
- #0
- print("0 and 1:",0 and 1)
- #0
- print("1 and 0:",1 and 0)
- #1
- print("1 and 1:",1 and 1)
- #[]
- print("[] and [1]:",[] and [1])
- #[]
- print("[1] and []:",[1] and [])
- #[1]
- print("[1] and [1]:",[1] and [1])
- #逻辑或运算符or:x or y 如果x为true则返回x,如果x为false则返回y
- #True
- print("false or true:",False or True)
- #True
- print("true or false:",True or False)
- #True
- print("true or true:",True or True)
- #1
- print("0 or 1:",0 or 1)
- #1
- print("1 or 0:",1 or 0)
- #1
- print("1 or 1:",1 or 1)
- #[1]
- print("[] or [1]:",[] or [1])
- #[1]
- print("[1] or []:",[1] or [])
- #[1]
- print("[1] or [1]:",[1] or [1])
- #逻辑非运算符not:not x 如果x为true则返回false,如果x为false则返回true
- #not 1 ==> False
- #not 0 ==> True
- list1 = [0,1,2,3,4]
- list2 = [0,1,2,3,4]
- print("list1 is:",list1)
- print("list2 is:",list2)
- print()
- #获取对象的id
- print("the id of list1 is:",id(list1))
- print("the id of list2 is:",id(list2))
- print()
- #获取对象的类型
- print("the type of list1 is:",type(list1))
- print("the type of list2 is:",type(list2))
- print()
- #获取对象的大小
- print("the size of list1 is:",sys.getsizeof(list1))
- print("the size of list2 is:",sys.getsizeof(list2))
- print()
- #判断两个对象引用是否相同,比较的是id,默认调用id()方法
- print("list1 and list2 is same:",list1 is list2)
- print()
- #判断两个对象值是否相同,比较的是value,默认调用__eq__()方法
- print("list1 and list2 is equal:",list1 == list2)
- print()
- #列表解析
- print("list1 comprehension:",[2*x for x in list1])
- print("list2 comprehension:",[3*x for x in list2])
- print()
- #列表切片
- print("list1[1:4] is:",list1[1:4])
- print("list2[1:4] is:",list2[1:4])
- print()