python循环语句和函数

1.使用for循环打印9*9乘法表

python 复制代码
for i in range(1, 10):
    for j in range(1, i+1):
        print(i, "*", j, "=", i*j, end="\t")
    print()

结果:

2.使用while循环打印9*9乘法表

python 复制代码
i = 1
while i < 10:
    j = 1
    while j < i+1:
        print(i, "*", j, "=", i*j, end="\t")
        j += 1
    i += 1
    print()

结果:

3.选做:使用while单层循环打印9*9乘法表

python 复制代码
i = 1
j = 1
while i < 10:
    if j > i:
        print()
        i += 1
        j = 1
        continue
    else:
        print(i, "*", j, "=", i * j, end="\t")
        j += 1

结果:

4.定义函数:

定义一个函数:函数的位置参数以及关键字参数的个数不确定

python 复制代码
def first_function(*args, **kwargs):
    return 0

定义一个函数:函数的前三个参数必须以位置参数形式参数传递,后边两个参数必须以关键字形式进行传递

python 复制代码
def second_function(i, j, k, /, *, m, n):
    return 0
相关推荐
抱抱宝13 分钟前
Pyecharts之特殊图表的独特展示
python·信息可视化·数据分析
deephub1 小时前
Python GIL(全局解释器锁)机制对多线程性能影响的深度分析
python·机器学习·gil
MatpyMaster2 小时前
基于PyQt5打造的实用工具——PDF文件加图片水印,可调大小位置,可批量处理!
python·pdf
go54631584652 小时前
python 从知网的期刊导航页面抓取与农业科技相关的数据
开发语言·python·科技
米码收割机2 小时前
【python】tkinter实现音乐播放器(源码+音频文件)【独一无二】
开发语言·python·pygame
星如雨グッ!(๑•̀ㅂ•́)و✧3 小时前
Java NIO全面详解
java·python·nio
笛柳戏初雪3 小时前
Python中的函数(下)
开发语言·python
码界筑梦坊3 小时前
基于Django的个人博客系统的设计与实现
后端·python·django·毕业设计
weixin_307779133 小时前
AWS EMR上的Spark日志实时搜索关键指标网页呈现的设计和实现
大数据·python·spark·云计算·aws