参考书目:《Learn Python The Hard Way》

cars=100
print('there are ',cars,'cars available.')
##练习5 更多变量打印
my_name='zxx'
my_age=22
my_height=162
my_weight='secret'
my_eyes='black'
my_teeth='white'
my_hair='black'
print("let's talk about %s."%my_name)
print("she's %d inches tall."%my_height)
print("she's weight is %s."%my_weight)
print("actully that's not too heavy.")
print("she's got %s eyes and %s hair."%(my_eyes,my_hair))
print("her teeth are usually %s depending on the coffe."%my_teeth)
print("if i add %d ,%d, i get %d."%(my_age,my_height,my_age+my_height))
print('%.2f'%2.6345) #保留两位小数(%后加.)
#%c 转换成字符(ASCII 码值,或者长度为一的字符串)
#%r 优先用repr()函数进行字符串转换(Python2.0新增)
#%s 优先用str()函数进行字符串转换
#%d / %i 转成有符号十进制数
#%u 转成无符号十进制数(阿拉伯数字1,2,3,4.....10)
#%o 转成无符号八进制数(0,1,2,...7;逢八进一)
#%x / %X (Unsigned)转成无符号十六进制数(x / X 代表转换后的十六进制字符的大小写)
#%e / %E 转成科学计数法(e / E控制输出e / E)
#%f / %F 转成浮点数(小数部分自然截断)
#%g / %G %e和%f / %E和%F 的简写
#%% 输出%
##练习6 字符串和文本
x="there are %d types of people."%10
binary='binary'
do_not="don't"
y="those who kown %s and those who %s."%(binary,do_not)
print(x)
print(y)
print("i said :%r."%x)
#将%r改成$s,x字符串输出的时候没有单引号,即%r输出有单引号
print("i also said :%s."%y)
hilarious=False
joke_evaluation="isn't that joke so funny?!%r"
print(joke_evaluation %hilarious)
w="this is the left side of..."
e="a string with a right side"
print(w+e) #字符串拼接
#字符串拼接其他方法:
print('%s%s'%(w,e))
##练习7 更多打印
print("marry had a little lamb.")
print("its fleece was white as %s."%'snow')
print("and everyone that mary went.")
print("."*10) #打印十个.
end1="C"
end2="h"
end3="e"
end4="e"
end5="s"
end6="e"
end7="B"
end8="u"
end9="r"
end10="g"
end11="e"
end12="r"
print (end1+end2+end3+end4+end5+end6,end=" ")
print(end7+end8+end9+end10+end11+end12) #在一行内打印,利用end参数end=""(无缝连接)end=" "(字符串间有空格)
##练习8 :打印,打印
formatter="%r %r %r %r"
print(formatter %(1,2,3,4))
print(formatter %("one","two","three","four")
print(formatter %("i had this thing.",
"that you could type up right.",
"but it didn't sing",
"so i said goodnight.")
)
#调试不成功的代码69-75
##练习9 打印,打印,打印
days="mon tue wed thu fri sat sun"
months="jan\nfeb\nmar\napr\nmay\njun\njul\naug" #\n换行标识符
print("here are the days:",days)
print("here are the months:",months)
print("""
there's something going on here.
with the three double-quotes.
we'll ba able to type as much as we like.
even 4 lines if we want,or 5,or 6.
""")
#"""三引号:打印多行字符串

4.26-python学习笔记(变量及命名、字符串、格式化字符串print,format,%...)的更多相关文章

  1. python学习笔记(十)之格式化字符串

    格式化字符串,可以使用format方法.format方法有两种形式参数,一种是位置参数,一种是关键字参数. >>> '{0} {1}'.format('Hello', 'Python ...

  2. python学习笔记(5-1)-基本数据类型-字符串类型及操作

    五.字符串处理函数  len(x):字符串x的长度.如len("12345")结果为5  str(x):任意类型x所对应的字符串形式. >>> str(123) ...

  3. python学习笔记:第四天( 字符串)

    Python3 字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 在Python2中,普通字符串是以8位ASCII码进行存储的,而Unicode字 ...

  4. Python学习笔记 变量

    蒟蒻高举横幅:部分内容转自廖雪峰的Python教学 1.Python是动态语言,即它的变量是没有类型的. !/usr/bin/env python a = 'ABC' print a a = 123 ...

  5. python学习笔记--文件重命名,删除及文件夹

    文件重命名 import os os.rename('123.txt','456.txt') 删除文件 >>> import os >>> os.remove('4 ...

  6. python学习笔记--变量和运算符

    一.变量命名规则 1.字母.数字.下划线组成 2.不以数字开头 3.关键字(也叫保留字),不能用作变量名 4.遵循PEP8命名规范 二.变量赋值 1.赋值符号 = 2.多重赋值 x=y=123 3.多 ...

  7. python学习笔记(2)--列表、元组、字符串、字典、集合、文件、字符编码

    本节内容 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1.列表和元组的操作 列表是我们以后最长用的数据类型之一,通过列表可以最方便的对数据实现最方便的存储.修改等操作 定 ...

  8. Python学习笔记摘要(一)类型 字符串 函数 列表 深浅拷贝

    python中的对象和类型 在python中,认为系统中的每一个"东西"都是一个对象,在python中,"对象"有着特殊的意义,python中的对象有: 一个标 ...

  9. Python学习笔记(四)——编码和字符串

    一.编码 1.编码类别: (1)ASCII码:127个字母被编码到计算机里,也就是大小写英文字母.数字和一些符号 (2)GB2312码:中国制定的用于加入中文汉字的编码 (3)Unicode:防止由于 ...

  10. Python学习笔记(四)——编码和字符串

    一.编码 1.编码类别: (1)ASCII码:127个字母被编码到计算机里,也就是大小写英文字母.数字和一些符号 (2)GB2312码:中国制定的用于加入中文汉字的编码 (3)Unicode:防止由于 ...

随机推荐

  1. git使用教程2-更新github上代码

    前面一篇已经实现首次上传代码到github了,迈出了装逼第一步,本篇继续讲如何把本地更新的代码同步更新到github上 一.clone代码 1.把大神的代码clone到本地,或者clone自己gith ...

  2. 转 linux设置开机服务自动启动/关闭自动启动命令 chkconfig

    原文连接http://blog.csdn.net/jiangguilong2000/article/details/8259360 chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行 ...

  3. 简单说说Spring Security 使用(附加验证码登录,自定义认证)

    先看官方文档:http://docs.spring.io/spring-security/site/docs/4.0.x/reference/htmlsingle/ spring security4已 ...

  4. 在 ServiceModel 客户端配置部分中,找不到引用协定“myservice.Service1Soap”的默认终结点元素。这可能是因为未找到应用程序的配置文件,或者是因为客户端元素中找不到与此协定匹配的终结点元素。

    在做项目的时候遇到这个问题,当我在web网站中引用webservice时,很正常,但是当我在一个类库里引用并调用webservice方法后,然后网站调用这个类库里的方法,就会报标题这样的错误.最后纠结 ...

  5. python ,__set__, __get__ 等解释

    @python __set__ __get__ 等解释 如果你和我一样,曾经对method和function以及对它们的各种访问方式包括self参数的隐含传递迷惑不解,建议你耐心的看下去.这里还提到了 ...

  6. Mysql分区表及自动创建分区Partition

    Range分区表建表语句如下,其中分区键必须和id构成主键和唯一键 CREATE TABLE `test1` ( `id` char(32) COLLATE utf8mb4_unicode_ci NO ...

  7. Odoo中Application与modules的区别

    转载请注明原文地址:https://www.cnblogs.com/cnodoo/p/9278681.html 一:Application(应用) application一般是针对大功能的模块,如提供 ...

  8. 【小游戏】flappy pig

    (1)这款游戏的画面很简单:一张背景图,始终就没有变过: (2)这款游戏的对象只有俩:一个小鸟(有三种挥动翅膀的状态)以及一对管道(有管道向上和向下两个方向): http://www.cnblogs. ...

  9. Django实战(一)之简单Demo

    菜鸟教程上Django安装可供参考: 参考链接: http://www.runoob.com/django/django-install.html 菜鸟教程上如果不行的话,下面博客网址可以供参考 Li ...

  10. win2003 HookPort 服务启动失败的解决办法!

    Win2003系统每次开机启动时都弹出个对话框报HookPort 服务启动失败,很多网友都遇到同类问题,问题根源是360安全卫士引起的,官方一直没有给出解决方案 问题描述:Win2003系统每次开机启 ...