网站首页 > 技术文章 正文
for循环嵌套
print(打印内容,end="")end=""指下一个打印内容并排输出。引号中间可以插入字符或变量。
'''
#如:
print("*"*2,end=" ")
print("*",end=" ")
print("*")
print("*",end="mm")#此处另起一行插入mm
sum=25
print("***",end="%d"%sum)#挺好入变量
'''
输出结果:
** * *
*mm***25
'''
#双for例:打印两层*号,每行4个
for imet in range(5):
for yemt in range(4):
print("*"*2, end=" ")
print()#控制换行
#或者
for imet in range(5):#外层循环控制行
print()#控制换行
for yemt in range(4):#内层循环控制列
print("*"*2, end=" ")
'''
例一,打印
# * # * # * # * # * # *
# * # * # * # * # * # *
# * # * # * # * # * # *
# * # * # * # * # * # *
# * # * # * # * # * # *
'''
for ime in range(5):
for yme in range(6):
print(" #",end=" *")
print()
#方法二
for i in range(5):
for j in range(6):
if j % 2==0:
print("*",end=" ")
else:
print("#",end=" ")
print()
'''
例二、打印
*
**
***
****
'''
#方法一
a=0
for i in range(4):
a+=1
for j in range(a):
print("*",end="")
print()
#方法二
for i in range(4):
for j in range(5):
print("*"*j)
#给列表[3,2,4,12,1,7]排序
猜你喜欢
- 2024-12-30 在 Python 中使用 f-String 格式化字符串
- 2024-12-30 CSnakes:在.NET项目中嵌入Python代码的工具
- 2024-12-30 10个小技巧,让你的 Python 代码更加优雅
- 2024-12-30 什么是Python中的DSL领域特定语言?
- 2024-12-30 PyScript:让Python在HTML中运行(python处理html文件)
- 2024-12-30 PythonNet:实现Python与.Net代码相互调用!
- 2024-12-30 Python嵌入版(python嵌入版区别)
- 2024-12-30 Python教程-嵌套字典(python字典嵌套字典取值)
- 2024-12-30 Python短文,Python中的嵌套条件语句(六)
- 2024-12-30 两分钟掌握Python中f-string 的用法
- 276℃Python短文,Python中的嵌套条件语句(六)
- 276℃python笔记:for循环嵌套。end=""的作用,图形打印
- 272℃PythonNet:实现Python与.Net代码相互调用!
- 266℃Python操作Sqlserver数据库(多库同时异步执行:增删改查)
- 266℃Python实现字符串小写转大写并写入文件
- 126℃原来2025是完美的平方年,一起探索六种平方的算吧
- 107℃Ollama v0.4.5-v0.4.7 更新集合:Ollama Python 库改进、新模型支持
- 107℃Python 和 JavaScript 终于联姻了!PythonMonkey 要火?
- 最近发表
-
- Python入门体验第二课教学反思:学情把握不准确,意外连连
- Python学不会来打我(95)python工厂函数知识点总结
- Python——使用reduce()方法(python函数reduce)
- Python每日一题(python输出每日一贴)
- Python学不会来打我(92)python代码调试知识总结(五)属性问题
- Python 的 __init__ 一起认识认识
- Python中 __init__的通俗解释是什么?
- Rocky Linux 9 系统初始化与安全加固脚本
- Python构建MCP服务器完整教程:5步打造专属AI工...
- Python的import都在用,可没人告诉我底层是这样的
- 标签列表
-
- python中类 (31)
- python 迭代 (34)
- python 小写 (35)
- python怎么输出 (33)
- python 日志 (35)
- python语音 (31)
- python 工程师 (34)
- python3 安装 (31)
- python音乐 (31)
- 安卓 python (32)
- python 小游戏 (32)
- python 安卓 (31)
- python聚类 (34)
- python向量 (31)
- python大全 (31)
- python次方 (33)
- python桌面 (32)
- python总结 (34)
- python浏览器 (32)
- python 请求 (32)
- python 前端 (32)
- python验证码 (33)
- python 题目 (32)
- python 文件写 (33)
- python中的用法 (32)