#冒泡排序
array = [1,2,3,6,5,4]
for i in range(len(array)):
for j in range(i):
if array[j] > array[j + 1]:
array[j], array[j + 1] = array[j + 1], array[j]
print(array)
#字符串格式化用法
x=123
so="%o"%x #8进制
print(so)
sh = "%x"%x #16进制
print(sh)
se='%e'%x
print(se)
print('%s'%65) #等价于str()
print('%s'%65333)
print('%d,%c'%(65,65)) #使用元组对字符串进行格式化,按位置进行对应
print(int('')) #可以使用int()函数将合法的数字字符串转化为整数
print('%s'%[1,2,3])
print(str([1,2,3])) #可以使用str()函数将任意类型数据转换为字符串
print(str((1,2,3)))
print(str({'A':65,'B':66})) #使用format()方法进行格式化,该法官法更加灵活,不仅可以使用位置进行格式化,还支持使用与位置无关的参数名来进行格式化,并且支持
#序列解包格式化字符串,为程序员提供非常大的方便
print('{0:.3f}'.format(1/3)) #保留3位小数
# 0.333
print("The number {0:,} in hex is: {0:#x},i oct is {0:#o}".format(55))
# The number 55 in hex is: 0x37,i oct is 0o67
print('The number {0:,} in hex is: {0:x},the number {1} inn oct is {1:o}'.format(555,55))
#The number 555 in hex is: 22b,the number 55 inn oct is 67
print('THe number {1} in hex is: {1:#x},the number {0} in oct is {0:#o}'.format(5555,55))
# THe number 55 in hex is: 0x37,the number 5555 in oct is 0o12663
print('My name is {name},my age is {age},and my QQ is {qq}'.format(name='zWrite',qq='122668xx',age=25))
# My name is zWrite,my age is 25,and my QQ is 122668xx
position =(5,6,12)
print('X:{0[0]};Y:{0[1]};Z:{0[2]}'.format(position)) #使用元组同时格式化多值
# X:5;Y:6;Z:12
weather = [('Monday','rain'),('Tuesday','sunny'),('Wednessday','sunny'),('Thursday','rain'),('Friday','cloudy')]
formatter='Weather of "{0[0]}" is "{0[1]}"'.format
for item in map(formatter,weather):
print(item)
# Weather of "Monday" is "rain"
# Weather of "Tuesday" is "sunny"
# Weather of "Wednessday" is "sunny"
# Weather of "Thursday" is "rain"
# Weather of "Friday" is "cloudy"
from string import Template
t = Template('My name is ${name},and is ${age} years old.') #创建模版
d = {'name':'zWrite','age':39}
t.substitute(d) #替换
print(t)
# <string.Template object at 0x101389198>
tt = Template('My name is $name,and is $age years old.')
tt.substitute(d)
print(tt)
# <string.Template object at 0x101389588>

最新文章

  1. SpringMvc的xml配置与annotation配置的例子的区别
  2. 为什么C语言中的数组序号都是从0开始
  3. C# 线程系列三 定时器线程
  4. IOS开发札记
  5. struts2 s:if标签以及 #,%{},%{#}的使用方法
  6. 最简洁粗暴版的虚拟用户配置FTP
  7. 一起刷LeetCode4-Median of Two Sorted Arrays
  8. 一个C#的XML数据库访问类
  9. ./scripts/feeds update -a OpenWrt大招系列
  10. C# 使用IENUMERABLE,YIELD
  11. 《大象UML》看书笔记2:
  12. 重新认识JavaScript里的数据类型
  13. 【jQuery】复选框的全选、反选,推断哪些复选框被选中
  14. 在 Vim 中设置 Tab 为4个空格
  15. XML fragments parsed from previous mappers already contains value for xxxxx
  16. 【TOGAF】总体认知
  17. Eclipse导出自己的项目(仅供自己保留方式war包)
  18. 常用且难记的一些css
  19. BZOJ4779: [Usaco2017 Open]Bovine Genomics
  20. Request参数值自动去空格

热门文章

  1. 限制UITextField的输入字数(长度)最正确的方法
  2. Protobuf-java maven配置
  3. Linux学习笔记 --iptables防火墙配置
  4. 理解WebKit和Chromium: 网页渲染的基本过程
  5. SpriteBuilder中pivot关节中的Collide bodies属性
  6. hbase thrift 定义
  7. hibernate链接数据库链接池c3p0配置
  8. 基于hashchange导航管理
  9. 基于event 实现的线程安全的优先队列(python实现)
  10. SQL遇到的问题