Python初级实战 | 直到今天,我终于学会99乘法表啦~

目录

一、print函数

1.1默认情况

1.2连接符sep

1.3末尾参数end

二、for语句

三、6种方式

方式1:for-for

方式2:for-while

方式3:while-for

方式4:while-while

方式5:使用递归函数

方式6:列表推导式


大家好,我是王某人

相信99乘法表大家都很熟悉,下面介绍如何使用Python来打印99乘法表。为了实现这个需求,前提需要掌握两个知识点:

  • print()函数的使用

  • for循环语句的使用

 

一、print函数

主要是掌握两个参数的使用:sep(连接符)和end(末尾换行符)

  • 连接符默认是:空格

  • 末尾符号默认是:换行

1.1默认情况

print("hello Peter")
hello Peter
print("hello","Peter")
hello Peter
print("hello Peter")
print("***********")
print("hello python")
hello Peter
***********
hello python

1.2连接符sep

从下面的例子中看到默认的连接符是空格

print("hello","Peter")
hello Peter

我们尝试使用不同的连接符来打印数据

print("hello","Peter",sep="+")  # 使用+
hello+Peter
print("hello","Peter",sep="-")  # 使用-
hello-Peter
print("hello","Peter",sep="***")  # 使用***
hello***Peter

1.3末尾参数end

末尾使用的参数

print("hello","Peter")  # 默认end情况
print("**************")
print("!!!!!!!!!!!!")
hello Peter
**************
!!!!!!!!!!!!
print("hello","Peter",end="\n")  # 默认就是换行
print("****************")
print("!!!!!!!!!!!!")
hello Peter
****************
!!!!!!!!!!!!

通过上面的例子,我们观察到:每次调用print函数都会自动换行。

因为这就是print默认的情况,末尾自动换行。通过使用end来进行改变

print("hello","Peter",end="\t")   # 制表符就是表格空格
print("****************", end="\t")
print("!!!!!!!!!!!!")
hello Peter	****************	!!!!!!!!!!!!
print("hello","Peter",end="|")   # 指定不同的默认符号
print("****************", end="+")
print("!!!!!!!!!!!!")

                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值