Python学习笔记5——while循环

把握今天,才能拥有明天!!!

while循环

benqian = 100000
year =0
while benqian < 200000:
    year+=1
    benqian=benqian*(1+0.067)
    print("第{0}年拿了{1}块钱".format(year,benqian))
第1年拿了106700.0块钱
第2年拿了113848.9块钱
第3年拿了121476.77629999998块钱
第4年拿了129615.72031209998块钱
第5年拿了138299.97357301068块钱
第6年拿了147566.07180240238块钱
第7年拿了157452.99861316333块钱
第8年拿了168002.34952024528块钱
第9年拿了179258.5069381017块钱
第10年拿了191268.8269029545块钱
第11年拿了204083.83830545243块钱

函数

大驼峰命名只能给类用 def 函数名(): 缩进 缩进

def func():
    print("我是一个函数")
#函数调用
func()
我是一个函数
## 函数的参数
def hello(person):
    print("{0},hello!".format(person))
p="Alihuhu"
hello(p)
Alihuhu,hello!
## return函数使用
def hello(person):
    print("{0},hello!".format(person))
    return '打完招呼啦!{0}不理我'.format(person)
p="Alihuhu"
a=hello(p)
print(a)
Alihuhu,hello!
打完招呼啦!Alihuhu不理我
# 九九乘法表
for row in range(1,10):
    for col in range(1,row+1):
        print(row*col)
    print()
1

2
4

3
6
9

4
8
12
16

5
10
15
20
25

6
12
18
24
30
36

7
14
21
28
35
42
49

8
16
24
32
40
48
56
64

9
18
27
36
45
54
63
72
81

查找函数帮助文档

# 查询print函数用法
help(print)
Help on built-in function print in module builtins:

print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
    
    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:  a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.
    end:   string appended after the last value, default a newline.
    flush: whether to forcibly flush the stream.
# 九九乘法表
for row in range(1,10):
    for col in range(1,row+1):
        print(row*col,end=" ")
    print()
1 
2 4 
3 6 9 
4 8 12 16 
5 10 15 20 25 
6 12 18 24 30 36 
7 14 21 28 35 42 49 
8 16 24 32 40 48 56 64 
9 18 27 36 45 54 63 72 81 

参数

  • http://cnblogs.com/bingabcd/p/6671368.html
  • 普通参数
  • 默认参数 def name(p1=v1,···):
  •      方法1:不注明,直接调用,自动赋值
  •      方法2:赋值,则不用默认参数,用赋值的参数
    •      挺重要的,可以偷懒
  • 关键字参数
  • 收集参数
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值