4.28-python学习笔记(转义符&input函数)
参考书目:《Learn Python The Hard Way》
##练习10
print("i am 6'2\"tall.")#将双引号转义
print('i am 6\'2"tall.')#将单引号转义
#打印出来的就是引号里的字符串,这个例子就是为了说明引号里出现同种引号怎么办
tabby_cat="\ti'm tabbled in." #\t空格(横向)
persian_cat="i'm split\non a line" #\n 新行
backslash_cat="i'm \\a\\ cat" #\\ 一个\
fat_cat='''
i'll do a list:
\t* Cat food
\t* Fishies
\t* Cathlp\n\t* Grass
'''
print(tabby_cat)
print(persian_cat)
print(backslash_cat)
print(fat_cat)
# 转义字符 描述
# \(在行尾时) 续行符
# \\ 反斜杠符号
# \' 单引号
# \" 双引号
# \a 响铃
# \b 退格(Backspace)
# \e 转义
# \000 空
# \n 换行
# \v 纵向制表符
# \t 横向制表符
# \r 回车
# \f 换页
# \oyy 八进制数,yy代表的字符,例如:\o12代表换行
# \xyy 十六进制数,yy代表的字符,例如:\x0a代表换行
# \other 其它的字符以普通格式输出
weather="ranning"
print("\t*today is %s"%weather) #格式化字符和转义序列放在一起 ## 练习11
print("How old are you?")
age=input()
print("How tall are you?")
height=input()
print("How much do you weigh?")
weight=input()
print("So,you're %s old,%s tall and %s heavy."%(age,height,weight))
#python3里将没有raw_input,只有input()
#input()它希望能够读取一个合法的 python 表达式,即你输入字符串的时候必须使用引号将它括起来,否则它会引发一个 SyntaxError
#input()就是让你输入啦
#最后一个print把%s换成%r的话,年龄、体重、身高会加上引号
#把三个input()改成input("age:"),input("height:"),input("weight:") ##练习12
age=input("How old are you?")
height=input("How tall are you?")
weight=input("How much do you weigh?")
print("So,you're %s old,%s tall and %s heavy."%(age,height,weight))22
#跟练习11一个意思,但是更加简练
4.28-python学习笔记(转义符&input函数)的更多相关文章
- Python学习笔记014——迭代工具函数 内置函数enumerate()
1 描述 enumerate() 函数用于将一个可遍历的数据对象(如列表.元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中. 2 语法 enumerate(sequ ...
- 05 python学习笔记-常用内置函数(五)
1.sorted() 函数对所有可迭代的对象进行排序(默认升序)操作 sort 与 sorted 区别: sort 是应用在 list 上的方法,sorted 可以对所有可迭代的对象进行排序操作. l ...
- python学习笔记十——模块与函数
第五章 模块与函数 5.1 python程序的结构 函数+类->模块 模块+模块->包 函数+类+模块+包=Python pyth ...
- Python学习笔记(九)—— 函数
一.函数调用: 1.python内部函数查询:http://docs.python.org/3/library/functions.html#abs 2.注意调用函数的参数个数和类型. 3.函数名其实 ...
- Python学习笔记3-字符串
格式化字符串/复合字段名 >>> import humansize >>> si_suffixes = humansize.SUFFIXES[1000] >& ...
- Python学习笔记5-字符串、bool、数值操作和数组字典排序
1.字符串 # 字符串数字之间转换 # x = int("6") # print type(x) #<type 'str'> # y = str(6) # print ...
- python学习笔记08-字符串
字符串是用单引号或者双引号引起来来的 单引号和双引号没有什么区别 1字符串支持乘法操作 >>> print('hello'*2) hellohello >>> 2 ...
- python学习笔记2-字符串操作
一.字符串切片 #切片也能适合字符串 tittle='今 天 发 苹 果' for i t in enumerate(tittle): #enumerate可以同时循环下标和值 print('%s:% ...
- python学习笔记15-字符串 lsit set truple之间的相互转换
import string #字符串转list str = 'abcde' list = list(str) #list转字符串 str_convert = ''.join(list) #字符串转se ...
随机推荐
- SP2-0734: unknown command beginning "lsnrctl st..." - rest of line ignored.
SP2-0734: unknown command beginning "lsnrctl st..." - rest of line ignored. Cause(原因):Comm ...
- 3星|《深度思考:不断逼近问题的本质》:香奈儿前CEO自传
深度思考:不断逼近问题的本质 作者是前香奈儿CEO,主要内容是作者的自传,从家庭说起,一直到卸任香奈儿CEO. 作者出生于上世纪六七十年代的一个美国中西部的犹太家庭,崇尚自由,讨厌标签.高中的一个暑假 ...
- MTK 官方 openwrt SDK 使用
来源 1.https://github.com/unigent/openwrt-3.10.14 上面有个 问题:SDK 缺少 linux-3.10.14-p112871.tar.xz 在 http ...
- [EffectiveC++]item21:Don't try to return a reference when you must return an object
- 021.5 IO流——字符流
###############基本功能写 FileWriter fw = new FileWriter("xxx.txt"); fw.write("哈喽"); ...
- Session not active, could not store state 的解决方法
1.开口加上session_start() http://metah.ch/blog/2014/05/facebook-sdk-4-0-0-for-php-a-working-sample-to-ge ...
- 随手练——HDU 1237 表达式求值(输入格式典型)
坑了老子半天,结果是 float 范围不够!!! 基本思想: 开一个符号栈,一个数字栈: 碰到数字就入栈,碰到符号就与栈顶符号进行对比,如果当前符号优先级小于栈顶符号,数字栈弹出两个数进行栈顶符号运算 ...
- Java50道经典习题-程序21 求阶乘
题目:求1+2!+3!+...+20!的和分析:使用递归求解 0的阶乘和1的阶乘都为1 public class Prog21{ public static void main(String[] ar ...
- 五子棋项目总结 JavaScript+jQuery(插件写法)+bootstrap(模态框)
Html部分(界面): 1.五子棋棋盘由canvas完成: 2.两个按钮,样式由bootstrap完成: 3.菜单按钮对应的模态框,可以选择游戏模式:玩家自由对战,和电脑对战,还可以指定谁先执子和哪个 ...
- 2、RabbitMQ-simplest thing(简单队列)
1.项目准备: 使用maven的依赖 <dependencies> <dependency> <groupId>com.rabbitmq</groupId&g ...