如何运用python里函数format

 时间:2024-10-16 16:30:23

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怎么配置邮箱?
  • 热门搜索
    我的世界怎么建城堡 山药手痒怎么办 斜刘海发型 怎么把手机格式化 学生发型 默认网关怎么设置 新加坡怎么样 顺其自然的近义词 皮肤松弛下垂怎么办 怎么查手机序列号