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
相关推荐
百锦再7 分钟前
第15章 并发编程
android·java·开发语言·python·rust·django·go
laufing15 分钟前
pyinstaller 介绍
python·构建打包
谅望者1 小时前
数据分析笔记09:Python条件语循环
笔记·python·数据分析
Auspemak-Derafru1 小时前
从U盘损坏中恢复视频文件并修复修改日期的完整解决方案
python
techzhi1 小时前
Intellij idea 注释模版
java·python·intellij-idea
李昊哲小课1 小时前
wsl ubuntu24.04 cuda13 cudnn9 pytorch 显卡加速
人工智能·pytorch·python·cuda·cudnn
温暖名字2 小时前
调用qwen3-omni的api对本地文件生成视频文本描述(批量生成)
python·音视频·qwen·qa问答
一眼万里*e3 小时前
搭建个人知识库
python
程序员小远3 小时前
软件测试之bug分析定位技巧
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·bug
江上清风山间明月4 小时前
Android 系统中进程和线程的区别
android·python·线程·进程