玩转Python语言之2:由点及线

# -*- coding: gb2312 -*-
"""
Created on Tue Sep 29 20:40:13 2015

@author: Administrator
"""

"""bool变量及运算Begin"""
"""
print "1+1是否等于2:",1+1==2
print "1+1是否等于3:",1+1==3

print "1+1不等于2",1+1 !=2
print "1+1不等于3",1+1 !=3

print "与运算",1+1==2 and 1+1==3

print "或运算",1+1==2 or 1+1 == 3

print "非运算",not 1+1 == 2

a=[1,2,3,4]
print "包含运算元素1是否在集合a中:",1 in a
print "包含运算元素6是否在集合a中:",6 in a
"""
"""bool变量及运算END"""

"""分岔路--if
light = "green"
if light =="red":
 print "Stop"
elif light == "green":
 print "Go"
else:
 print "show down"
"""

"""循环轮转--while
 
sum = 0
i = 1
 
while i <= 100:
  sum = sum + i
  i = i + 1
print sum

"""
 
 

"""有一个轮转 --for
num = [0,1,2,3,4]
for i in num:
    print i
print "------万恶的分界线------"
for i in num:
    print i+1
    
contact ={"Lilei":"012312","Hanmeimei":"123123"}
for i in contact:
    print i,contact[i]
 """
 
 
"""循环控制
num = [0,1,2,3,-4,5]
for i in num:
   if i<0:
       break
   print i
print  "------万恶的分界线------"   
for i in num:
   if i<0:
       continue
   print i 
 """
 
 
"""操作打包--函数

num = [1,2,3,4,5]
def addsum(num):
  sum = 0
  for i in num:
    sum = sum + i
  return sum      

num2 = [1,2,2,4,5,8]

print "集合num1求和",addsum(num)
print "集合num2求和",addsum(num2)
"""
 
"""作用域
x=1

def change():
    x=10
    print "x in function",x 
change()
print x

print  "------万恶的分界线------"   

def change1():
    global x
    x=10
    print "x in function",x 
change1()
print x
"""
 
"""函数重打包--模块
import math
print math.pi
print math.sin(math.pi/2)

print "模块包帮助中心",dir(math)
"""
 

 

posted @ 2015-09-29 23:39  Mander_Gao  阅读(249)  评论(0编辑  收藏  举报