# %s可以接收一切 %d只能接收数字
msg = 'i am %s my hobby is %s' %('lhf','alex')
print msg
msg2 = 'i am %s my hobby is %d' %('lhf',1)
print msg2 #打印浮点数
tpl ="percent %.2f" %99.976 #截取几位
print tpl
tpl2 = "i am %(name)s age %(age)d" %{"name":"alex","age":18}
print tpl2 msg3 = 'i am %(name)-60s' % {"name":"wangyue"}
print msg3 print ('root','x','6',sep=':')

Python 百分号字符串拼接的更多相关文章

  1. py-day2-5 python 百分号字符串拼接

    #### 字符串格式化. # %s 代替任何的元素 (数字,字符串,列表··) print('I live %s crty' %'my') print('I live %s crty' %'[6,8, ...

  2. day14 Python百分号字符串拼接

    拼接 # -*- coding:utf8 -*- #%s字符串,%d数字msg = '%s am %s my %s is %s'% (2,"charon","pluto& ...

  3. Python中字符串拼接的三种方式

    在Python中,我们经常会遇到字符串的拼接问题,在这里我总结了三种字符串的拼接方式:     1.使用加号(+)号进行拼接 加号(+)号拼接是我第一次学习Python常用的方法,我们只需要把我们要加 ...

  4. Python中字符串拼接的N种方法

    python拼接字符串一般有以下几种方法: ①直接通过(+)操作符拼接 s = 'Hello'+' '+'World'+'!'print(s) 输出结果:Hello World! 使用这种方式进行字符 ...

  5. Python 基础 字符串拼接 + if while for循环

    注释单行注释 #多行注释 ''' 三个单引号或者三个双引号 """ ''' 用三引号引住可以多行赋值 用户交互 input 字符串拼接 +  ""%( ...

  6. python之字符串拼接:%和format

    使用百分号拼接字符串: 例如: msg='i am %s my hobby is...' %'abc' print(msg) 如果需要用2个%s呢?就使用括号例如: msg='I am %s my h ...

  7. python字符串拼接

    Python字符串拼接 在Python的实际开发中,很多都需要用到字符串拼接,python中字符串拼接有很多,今天总结一下: 用+符号拼接 用%符号拼接 用join()方法拼接 用format()方法 ...

  8. Python基础-字符串格式化_百分号方式_format方式

    Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...

  9. 最全面的 python 字符串拼接总结(带注释版)

    在 Python 中字符串连接有多种方式,这里简单做个总结,应该是比较全面的了,方便以后查阅. 加号连接 第一种,通过+号的形式: >>> a, b = 'hello', ' wor ...

随机推荐

  1. [译] OpenStack Ocata 版本中的 53 个新功能盘点

    原文链接:https://www.mirantis.com/blog/53-new-things-to-look-for-in-openstack-ocata/ 原文作者:Nick Chase, Ra ...

  2. [转][EasyUI]扩展 DateBox

    /** * 给时间框控件扩展一个清除的按钮 */ $.fn.datebox.defaults.cleanText = '清空'; (function ($) { var buttons = $.ext ...

  3. 廖雪峰Java5集合-4Set-1使用Set

    集合 Set用于存储不重复的元素集合: boolean add(E e) boolean remove(Object o) boolean contains(Object o) int size() ...

  4. centos6.8下pptp客户端的安装配置

    原文: https://blog.csdn.net/zhang11321132/article/details/20612473 yum -y install ppp pptp pptp-setup ...

  5. 使用CacheCloud管理Redis实例

    转载来源:http://www.ywnds.com/?p=10610 一.CacheCloud是什么? 最近在使用CacheCloud管理Redis,所以简单说一下,这里主要说一下我碰到的问题.Cac ...

  6. SAS 报表输出一些新式控制

    SAS 报表输出一些新式控制 *******************************:*Purpose: 报表*Programm: *Programmor: *Date: *Version: ...

  7. BCGcontrolBar(六) RibbonBar编辑

    BCGcontrolBar 可以使用 Ribbon Designer方便的对 Ribbon条进行编辑 文件位置为 C:\Program Files\BCGSoft\BCGControlBarPro\D ...

  8. sqoop导出mysql数据进入hive错误

    看mr的运行显示:sqoop job可以获得的select max(xxx)结果,但是当mr开始时却显示大片错误,就是连接超时,和连接重置等问题, 最后去每个节点ping mysql的ip地址,发现 ...

  9. Android购物车的实现,仿淘宝天猫京东等APP。处理RecyclerView或listview中的选中事件;

    很久之前的代码了,拉出来晾晾! 购物车大致思路: 分为:商品.店铺.全选: 商品全部选中后--店铺自动选中:商品未全部选中(若有一个商品未选中)--店铺不选中. 店铺全部选中后--全选自动选中:店铺未 ...

  10. python第三方库,你要的这里都有

    Python的第三方库多的超出我的想象. python 第三方模块 转 https://github.com/masterpy/zwpy_lst   Chardet,字符编码探测器,可以自动检测文本. ...