#!/usr/bin/env python
# -*- coding:utf8 -*-
#******************语句***********************
#一般连贯语句以冒号结尾':' 次行代码缩进 缩进结束(没有大括号的代码块) 代码执行结束 删除括号() 没有冒号 终止行就是终止语句
x = 1
y = 2
if x < 1 :
x = "1"
y = '2'
elif x == 1:
x = '2'
y = '3'
print (x,y)
a,b = 0,1
while b<10:
print (b)
a,b = b,a+b
# zip 迭代器
p1 = [2,3,5,6]
p1.append(10)
for i in p1:
i**2
print (p1)
p2 = [0,1,2]
p3 = list(zip(p1,p2))
print (p3) # [(2, 0), (3, 1), (5, 2)]
#迭代器 以C语言运行速度运行
num1 = iter(p3)
print (next(num1)) # (2, 0)
print (next(num1)) # (3, 1)
print (next(num1)) # (5, 2)
#函数声明
def f1(s):
print (s)
f1(10) #10
#函数嵌套声明
def f2(ss):
if ss <10:
def f3():
print (10 -ss)
return f3()
else:print (ss)
f2(9) #1
def f4(**a): #参数为字典 *a为元组
print (a)
f4(a=1) # {'a': 1}
网友评论