print("hello  {leon}".format(leon="world!"))    #format 是一个格式化字符穿的方法。
print("hello {0} i am {1}".format("tom","leon"))
print("hello {} i am {}".format("tom","leon")) username = 'leon' #定义username
print("welcome user {name} login ... ".format(name=username)) #引用username

  打印结果:

C:\Python36\python.exe H:/leon/day1/input.py
hello world!
hello tom i am leon
hello tom i am leon
welcome user leon login ... Process finished with exit code 0

格式化字符串--format用法的更多相关文章

  1. Python中用format函数格式化字符串的用法

    这篇文章主要介绍了Python中用format函数格式化字符串的用法,格式化字符串是Python学习当中的基础知识,本文主要针对Python2.7.x版本,需要的朋友可以参考下   自python2. ...

  2. Python 的格式化字符串format函数

    阅读mattkang在csdn中的博客<飘逸的python - 增强的格式化字符串format函数>所做笔记 自从python2.6开始,新增了一种格式化字符串的函数str.format( ...

  3. 【python】format函数格式化字符串的用法

    来源:http://www.jb51.net/article/63672.htm 自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足.那么,他跟之前的%型格式 ...

  4. VBA 格式化字符串 - Format大全

    VBA 格式化字符串 VBA 的 Format 函数与工作表函数 TEXT 用法基本相同,但功能更加强大,许多格式只能用于VBA 的 Format 函数,而不能用于工作表函数 TEXT ,以下是本人归 ...

  5. Python - 格式化字符串的用法

    0. 摘要 Python支持多种格式化字符串的方法,包括%-fromatting.str.format().f-strings三种,f-strings是Python3.6以后出现的一种新方法,相比其他 ...

  6. 飘逸的python - 增强的格式化字符串format函数

    自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足.那么,他跟之前的%型格式化字符串相比,有什么优越的存在呢?让我们来揭开它羞答答的面纱. 语法 它通过{}和 ...

  7. 格式化字符串format函数

    自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足.那么,他跟之前的%型格式化字符串相比,有什么优越的存在呢?让我们来揭开它羞答答的面纱. 语法 它通过{}和 ...

  8. Python格式化字符串--format

    format格式化字符串方法相较于老版%格式方法的优点: 1.不需要理会数据类型的问题,在%方法中'%s'只能替代字符串类型. 2.单个参数可以多次输出,参数顺序可以不相同. 3.填充方式十分灵活,对 ...

  9. (转)飘逸的python - 增强的格式化字符串format函数

    原文:https://blog.csdn.net/handsomekang/article/details/9183303 Python字符串格式化--format()方法-----https://b ...

随机推荐

  1. linux 内核经典面试题

    http://blog.chinaunix.net/uid-25909619-id-3376158.html

  2. 【BZOJ】3403: [Usaco2009 Open]Cow Line 直线上的牛(模拟)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3404 裸的双端队列.. #include <cstdio> #include <c ...

  3. 手动编译svn

    #!/bin/bash yum -y remove subversionmkdir -p /dist/{dist,src}cd /dist/dist/bin/rm -f openssl* subver ...

  4. flask渲染模板

    Flask自身使用了jinja2模板,可以使用render_template()方法来渲染模板,只需要将模板名和关键字的参数传入. 该渲染模板的模块(views.py)会在 templates 文件夹 ...

  5. Android开发:《Gradle Recipes for Android》阅读笔记(翻译)5.4——使用Espresso测试Activity

    问题: 你想要使用Google的Espresso测试Activity. 解决方案: 在Gradle配置里面增加Espresso,书写测试脚本. 讨论: Espresso测试库已经被添加进“Androi ...

  6. 《ASP.NET 1200例》ref关键字与out关键字

    REF关键字 ref 关键字会导致通过引用传递的参数,而不是值. 通过引用传递的效果是在方法中对参数的任何改变都会反映在调用方的基础参数中. 引用参数的值与基础参数变量的值始终是一样的. 不要将“通过 ...

  7. android应用安全——代码安全(android代码混淆)

    android2.3的SDK开始在eclipse中支持代码混淆功能(理论上java都支持混淆,但关键在于如何编写proguard的混淆脚本,2.3的SDK使用简单的配置就可以实现混淆).使用SDK2. ...

  8. .Net Core 知识了解:一跨平台的奥秘

    学习一下.Net Core 查看了技术大拿的文章 .NET Core跨平台的奥秘[上篇]:历史的枷锁 一下是学习资料 对于计算机从业人员来说,“平台(Platform)”是一个我们司空见惯的词语,在不 ...

  9. iOS 更改uitextfield placeholder颜色

    [passwordField setValue:TPColor forKeyPath:@"_placeholderLabel.textColor"];

  10. [LeetCode] Reverse Lists

    Well, since the head pointer may also be modified, we create a new_head that points to it to facilit ...