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 ...
随机推荐
- VC 6.0 MFC关闭对话框在win7出现崩溃的情况
Ctrl + W 掉出来class管理 添加OnDestory方法 void CPackUpItemToSetDlg::OnDestroy() { exit(1); CDialog::OnDestro ...
- 荣禄[róng lù]
荣禄[róng lù] 百科名片 荣禄 荣禄(1836年4月6日-1903年4月11日)清末大臣,晚清政治家.字仲华,号略园,瓜尔佳氏,满洲正白旗人,出身于世代军官家庭,以荫生晋工部员外郎,后任内务府 ...
- Python、R对比分析
一.Python与R功能对比分析 1.python与R相比速度要快.python可以直接处理上G的数据:R不行,R分析数据时需要先通过数据库把大数据转化为小数据(通过groupby)才能交给R做分析, ...
- Java日期格式化参数对照表
Symbol Meaning Presentation Example G era designator Text AD y year Number 2009 M month in year Text ...
- scala流程控制语句以及方法和函数
1.if else表达式 scala中没有三目运算符,因为根本不需要.scala中if else表达式是有返回值的,如果if或者else返回的类型不一样,就返回Any类型(所有类型的公共超类型). 例 ...
- 015.2Condiction接口
Condiction对象能够让线程等待,也能够唤醒相应的线程,通过下面方法,具体看代码:await();signal();signalAll(); 使用步骤:1)创建锁2)通过锁拿到Condictio ...
- 【1】【MOOC】Python游戏开发入门-北京理工大学【第二部分-游戏开发之框架】
学习地址链接:http://www.icourse163.org/course/0809BIT021E-1001873001?utm_campaign=share&utm_medium=and ...
- Spring(六)之自动装配
一.自动装配模型 下面是自动连接模式,可以用来指示Spring容器使用自动连接进行依赖注入.您可以使用元素的autowire属性为bean定义指定autowire模式. 可以使用 byType 或者 ...
- [AHOI2001]多项式乘法
\([Link](https://www.luogu.org/problemnew/show/P2553)\) \(\color{red}{\mathcal{Description}}\) 给出两个多 ...
- CGContextRef 用法总结
0 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文1 CGContextMoveToPoint 开始画线2 CGContext ...