py-day2-5 python 百分号字符串拼接
#### 字符串格式化。
# %s 代替任何的元素 (数字,字符串,列表··)
print('I live %s crty' %'my')
print('I live %s crty' %'[6,8,9]')
I live my crty
I live [6,8,9] crty # %s -- %( ) 可以代替多个元素
print('I live %s crty,prefer live %s country' %('your','my')) I live your crty,prefer live my country # %d 表示代替数字 也只能接收数字
msg = 'i an %s my age is %d'%('xiaoma',18)
print(msg) i an xiaoma my age is 18 # 打印浮点数 默认保留小数点后6位数 并四舍五入
msg = 'percent %f'%3.1415926
print(msg) percent 3.141593 msg1 = 'percent %.2f'%3.1415926 #(%.2f 保留小数点后2位数 )
print(msg1) percent 3.14 # 百分比
msg2 = 'percent %f %%'%3.1415926
print(msg2) percent 3.141593 % msg3 = 'percent %.2f %%'%3.1415926
print(msg3) percent 3.14 %
# 以字典的形式上传
msg = 'i am %(name)s my age is %(age)d' % {'name':'xiaoma','age':18}
print(msg) i am xiaoma my age is 18
# + - 是调节左右宽度 \033[色号;1m --- \033[0m (表示填充颜色)
test = 'i am %-20s my hobby is %s' %('mj',18)
print(test)
test1 = 'i am %+20s my hobby is %s' %('mj',18)
print(test1) i am mj my hobby is 18
i am mj my hobby is 18 msg = 'i am \033[43;1m%(name)+20s\033[0m my hobby is alex' %{'name':'majun'}
print(msg)

# 符号拼接
print('rood','x','uid','eid',sep= ':')
print('rood','x','uid','eid',sep= "-") rood:x:uid:eid
rood-x-uid-eid
py-day2-5 python 百分号字符串拼接的更多相关文章
- day14 Python百分号字符串拼接
拼接 # -*- coding:utf8 -*- #%s字符串,%d数字msg = '%s am %s my %s is %s'% (2,"charon","pluto& ...
- Python 百分号字符串拼接
# %s可以接收一切 %d只能接收数字 msg = 'i am %s my hobby is %s' %('lhf','alex') print msg msg2 = 'i am %s my hobb ...
- Python中字符串拼接的三种方式
在Python中,我们经常会遇到字符串的拼接问题,在这里我总结了三种字符串的拼接方式: 1.使用加号(+)号进行拼接 加号(+)号拼接是我第一次学习Python常用的方法,我们只需要把我们要加 ...
- Python中字符串拼接的N种方法
python拼接字符串一般有以下几种方法: ①直接通过(+)操作符拼接 s = 'Hello'+' '+'World'+'!'print(s) 输出结果:Hello World! 使用这种方式进行字符 ...
- Python 基础 字符串拼接 + if while for循环
注释单行注释 #多行注释 ''' 三个单引号或者三个双引号 """ ''' 用三引号引住可以多行赋值 用户交互 input 字符串拼接 + ""%( ...
- python之字符串拼接:%和format
使用百分号拼接字符串: 例如: msg='i am %s my hobby is...' %'abc' print(msg) 如果需要用2个%s呢?就使用括号例如: msg='I am %s my h ...
- python字符串拼接
Python字符串拼接 在Python的实际开发中,很多都需要用到字符串拼接,python中字符串拼接有很多,今天总结一下: 用+符号拼接 用%符号拼接 用join()方法拼接 用format()方法 ...
- Python基础-字符串格式化_百分号方式_format方式
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...
- 最全面的 python 字符串拼接总结(带注释版)
在 Python 中字符串连接有多种方式,这里简单做个总结,应该是比较全面的了,方便以后查阅. 加号连接 第一种,通过+号的形式: >>> a, b = 'hello', ' wor ...
随机推荐
- elbow 求拐点
distancePointLine <- function(x, y, slope, intercept) { ## x, y is the point to test. ## slope, ...
- day050 前端Jquery库的使用
一.导入jquery文件 <script src=" jquery库文件"></script> 二.选择标签 >>概念明晰: $是jQuery类 ...
- Hyperledger fabric-sdk-java Basics Tutorial(转)
原文地址:Hyperledger fabric-sdk-java Basics Tutorial This quick tutorial is for all Java developers, who ...
- Python- - -练习目录
练习题 1,简述变量命名规范 1.必须是字母,数字,下划线的任意组合: 2.不能是数字开头: 3.不能是python中的关键字: 4.变量不能是中文: 5.变量不能过长: 6.变量要具有可描述性: 2 ...
- IO流的分类
按内容分:字节流和字符流 按流向分:输入流和输出流 字节流: 输入流:InputStream 输出流:OutputStream 字符流: 输入流:FileReader 输出流:FileWriter
- Linux进程间通信机制
Linux支持管道.信号.unix system V三种IPC(Inter-Process-Communication)机制.以下分别对三种机制加以简单介绍. 一.信号机制: 信号又称作软中断,用来通 ...
- Oracle 监听器日志配置与管理
十一假期间,某客户因为监听日志问题导致系统登录挂起,当时在返京的路上,因客户业务不允许中断,无奈之下,借了个本子帮客户做了紧急处理,今天恰好有空,在网上搜了下有关监听日志的内容,发现一个不错的帖子,内 ...
- mysql 表中已经存在数据 修改字段类型 varchar(11) 改为 int(11)
update tablename set s_role = '' alter table tablename modify column s_role int(11)
- 由通过seeion识别保存在cookie中的seeionID引发的CSRF问题
上图是一个完整的CSRF攻击过程解释图 重点是第三句话 用户在没有登出的情况下,被攻击者获得了SESSIONID信息,伪造真用户登录 二.CSRF防御 通过 referer.token 或者 验证码 ...
- nginx优化参考
参考链接:http://blog.sina.com.cn/s/blog_4f9fc6e10102uxib.html 计算访问路径频度 awk -r|more |grep /路径 ps print &a ...