如何运用python里函数format

 时间:2026-02-14 02:43:46

1、打开PYTHON,新建一个PY文档。

如何运用python里函数format

2、abc = "Peter %d %s %2.5f" %(888, "Pan", 72.1)

abc

第一种方法就是运用%,但是我们需要定义后面跟的是什么类型。

如何运用python里函数format

3、abc = "Peter %d %s %2.5f" %("Pan", 72.1, 888)

如果对应的顺序错误,返回值会报错。

如何运用python里函数format

4、help(abc.format)

查看一下另一种形式的用法。

如何运用python里函数format

5、ttt = "I am {}".format("Ben")

print(ttt)

aaa = "The number is {}".format(3)

print(aaa)

bbb = "This is python {} version".format(3.0)

print(bbb)

这种方法不用事先定义需要输入的类型。

如何运用python里函数format

6、ccc = "{} is using python {} version".format("Alice", 2.74)

print(ccc)

不仅可以定义一个,还可以定义多个。

如何运用python里函数format

7、date = "2099/2/4"

week = "Monday"

kkk = f"The meeting will be set up on {week} which is {date}."

print(kkk)

这是一种新的方法,在更新版本里面有,需要先定义变量。

如何运用python里函数format

  • WPS的演示文稿文本框如何更改线条的端点类型
  • 如何运行第一个python程序?
  • 台安继电器SG2系列说明书:[1]
  • win10解决U盘文件无权限访问,图片打不开
  • Foxmail怎么配置邮箱?
  • 热门搜索
    营养不良怎么办 qq设备锁怎么解除 包包子怎么发面 呈现的近义词 怎么换苹果手机铃声 忽略的近义词 为什么感冒会流鼻涕 怎么祛青春痘 吸盘吸不住怎么办 太阳的后裔宋慧乔发型