首页 > 编程语言 >python中的print()

python中的print()

时间:2023-01-02 21:55:56浏览次数:43  
标签:24 10 12 16 python 18 print

python中的print函数有个end参数特别有用:

1 for i in range(1, 10):
2     for j in range(1, i + 1):
3         print(f'{j} * {i} = { i * j}')
4     print()

结果:

 1 1 * 1 = 1
 2 
 3 1 * 2 = 2
 4 2 * 2 = 4
 5 
 6 1 * 3 = 3
 7 2 * 3 = 6
 8 3 * 3 = 9
 9 
10 1 * 4 = 4
11 2 * 4 = 8
12 3 * 4 = 12
13 4 * 4 = 16
14 
15 1 * 5 = 5
16 2 * 5 = 10
17 3 * 5 = 15
18 4 * 5 = 20
19 5 * 5 = 25
20 
21 1 * 6 = 6
22 2 * 6 = 12
23 3 * 6 = 18
24 4 * 6 = 24
25 5 * 6 = 30
26 6 * 6 = 36
27 
28 1 * 7 = 7
29 2 * 7 = 14
30 3 * 7 = 21
31 4 * 7 = 28
32 5 * 7 = 35
33 6 * 7 = 42
34 7 * 7 = 49
35 
36 1 * 8 = 8
37 2 * 8 = 16
38 3 * 8 = 24
39 4 * 8 = 32
40 5 * 8 = 40
41 6 * 8 = 48
42 7 * 8 = 56
43 8 * 8 = 64
44 
45 1 * 9 = 9
46 2 * 9 = 18
47 3 * 9 = 27
48 4 * 9 = 36
49 5 * 9 = 45
50 6 * 9 = 54
51 7 * 9 = 63
52 8 * 9 = 72
53 9 * 9 = 81

下面代码:

1 for i in range(1, 10):
2     for j in range(1, i + 1):
3         print(f'{j} * {i} = { i * j}', end='\t')
4     print()

结果为:

1 1 * 1 = 1    
2 1 * 2 = 2    2 * 2 = 4    
3 1 * 3 = 3    2 * 3 = 6    3 * 3 = 9    
4 1 * 4 = 4    2 * 4 = 8    3 * 4 = 12    4 * 4 = 16    
5 1 * 5 = 5    2 * 5 = 10    3 * 5 = 15    4 * 5 = 20    5 * 5 = 25    
6 1 * 6 = 6    2 * 6 = 12    3 * 6 = 18    4 * 6 = 24    5 * 6 = 30    6 * 6 = 36    
7 1 * 7 = 7    2 * 7 = 14    3 * 7 = 21    4 * 7 = 28    5 * 7 = 35    6 * 7 = 42    7 * 7 = 49    
8 1 * 8 = 8    2 * 8 = 16    3 * 8 = 24    4 * 8 = 32    5 * 8 = 40    6 * 8 = 48    7 * 8 = 56    8 * 8 = 64    
9 1 * 9 = 9    2 * 9 = 18    3 * 9 = 27    4 * 9 = 36    5 * 9 = 45    6 * 9 = 54    7 * 9 = 63    8 * 9 = 72    9 * 9 = 81

看看哪种更合适吧

标签:24,10,12,16,python,18,print
From: https://www.cnblogs.com/guochaoxxl/p/17020628.html

相关文章

  • Python 文件操作(IO 技术)
    目录Python文件操作(IO技术)文本文件和二进制文件文件操作相关模块概述建文件对象open()文本文件的写入write()/writelines()写入数据close()关闭文件流with语句(上下......
  • Smtp Oauth With Python
     我的博客园:https://www.cnblogs.com/CQman/GitHub#基于Python语言的smtpOauth连接世纪互联运营的Office365(或21VO365)的邮箱 AuthenticateanIMAP,POPorSM......
  • C++/python共享内存交换图片/文本信息
    共享内存保存读取图片OpenShare.cpp#include"OpenShare.h"//共享内存1,,C++发--python传递位姿与图像存储路径intkey_id=1111;intshmid;void*pBuffer;//共......
  • 用python爬取网络文章----滴天髓
    用python爬取网络文章真的很简单。主要分以下几个步骤1、安装并导入相关模块.这里我们要用到两个模块,分别是reqesets和lxml安装命令pipinstallrequests和pipinstall......
  • python+Django学习资源汇总-更新中
    ​​Python教程​​​​Python3.7.4文档​​​​Python基础教程​​​​Python教程​​​​Python入门​​ ​​python+django搭建web项目​​​​PythonDjango(WEB电......
  • 2D Pose人体关键点实时检测(Python/Android /C++ Demo)
    2DPose人体关键点实时检测(Python/Android/C++Demo)目录​​2DPose人体关键点实时检测(Python/Android/C++Demo)​​​​1.人体关键点数据集​​​​(1)COCO数据集​​......
  • 双目三维重建系统(双目标定+立体校正+双目测距+点云显示)Python
    双目三维重建系统(双目标定+立体校正+双目测距+点云显示)Python目录​​双目三维重建系统(双目标定+立体校正+双目测距+点云显示)Python​​​​1.项目结构​​​​2.Envir......
  • django与python版本对应关系 附加djangorestframework框架
    Django与python版本Django1.11版本兼容Python2.7、3.4、3.5、3.6、3.7(addedin1.11.17)#1.11.5python<=3.6Django2.0版本兼容Python3.4、3.5、3.6、3.7Djang......
  • python 使用 VSCode 入门简介
    本文主要介绍如何使用VSCode创建、编辑、运行、调试hello.py程序,对如何安装使用python不做介绍,也不对安装vscode介绍。准备事项电脑安装python3,vscode,并安装v......
  • Python pip3用国内源安装
    国内可用的源如下:清华:https://pypi.tuna.tsinghua.edu.cn/simple中国科技大学https://pypi.mirrors.ustc.edu.cn/simple/华中理工大学:http://pypi.hustunique.com/山东理工......