参考书目:《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函数)的更多相关文章

  1. Python学习笔记014——迭代工具函数 内置函数enumerate()

    1 描述 enumerate() 函数用于将一个可遍历的数据对象(如列表.元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中. 2 语法 enumerate(sequ ...

  2. 05 python学习笔记-常用内置函数(五)

    1.sorted() 函数对所有可迭代的对象进行排序(默认升序)操作 sort 与 sorted 区别: sort 是应用在 list 上的方法,sorted 可以对所有可迭代的对象进行排序操作. l ...

  3. python学习笔记十——模块与函数

    第五章 模块与函数 5.1 python程序的结构 函数+类->模块              模块+模块->包                 函数+类+模块+包=Python pyth ...

  4. Python学习笔记(九)—— 函数

    一.函数调用: 1.python内部函数查询:http://docs.python.org/3/library/functions.html#abs 2.注意调用函数的参数个数和类型. 3.函数名其实 ...

  5. Python学习笔记3-字符串

    格式化字符串/复合字段名 >>> import humansize >>> si_suffixes = humansize.SUFFIXES[1000] >& ...

  6. Python学习笔记5-字符串、bool、数值操作和数组字典排序

    1.字符串 # 字符串数字之间转换 # x = int("6") # print type(x) #<type 'str'> # y = str(6) # print ...

  7. python学习笔记08-字符串

    字符串是用单引号或者双引号引起来来的  单引号和双引号没有什么区别 1字符串支持乘法操作 >>> print('hello'*2) hellohello >>> 2 ...

  8. python学习笔记2-字符串操作

    一.字符串切片 #切片也能适合字符串 tittle='今 天 发 苹 果' for i t in enumerate(tittle): #enumerate可以同时循环下标和值 print('%s:% ...

  9. python学习笔记15-字符串 lsit set truple之间的相互转换

    import string #字符串转list str = 'abcde' list = list(str) #list转字符串 str_convert = ''.join(list) #字符串转se ...

随机推荐

  1. Xcode 下载地址 与Macos版本要求

    Xcode下载地址:https://developer.apple.com/download/more/ 参考文档:https://zh.wikipedia.org/wiki/Xcode

  2. jquery-validation验证插件

    参考网站:菜鸟教程 一.导入js <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/j ...

  3. strerror的坑

    最近写的一段代码,总是出core,精简了一下,稳定复现. #include <stdio.h> #include <errno.h> int main() { printf(& ...

  4. 使用plugins让打包更便捷

    之前运行dist下的js,都是手动把index.html拷贝过去的,每次把dist文件夹删除,都需要将index.html拷贝进去,这样很麻烦,我们在webpack官方插件中找到HtmlWebpack ...

  5. keras写模型时遇到的典型问题,也是最基础的类与对象问题

    自己定义了一个卷积类,现在需要把卷积加入model中,我的操作是这样的: model.add(Convolution1dLayer) 这样就会报错: 正确的写法是: model.add(Convolu ...

  6. docker启动容器关于防火墙报错

    在重启docker工程时候出错: [root@hadoop-alone ~]# docker start padError response from daemon: driver failed pr ...

  7. ListView 中的TextView实现跑马灯效果

    案例:怎么样在一个ListView中含有TextView的item中实现字母滚动呢.这个在一些特定的场合经常用得到.如下图,当焦点位于某个item的时候其内容就自动滚动显示 要实现这样的效果,废话不多 ...

  8. C++设计一个不能被继承的类

    1. 方法一 将构造函数和析构函数设置为私有函数,重新定义公有的静态函数来创建和释放类. #include "stdafx.h" #include <iostream> ...

  9. f-stack中nginx配置后make出现error: ignoring return value of ‘ftruncate’

    问题 Nginx 配置后 make 出现error: src/os/unix/ngx_process_cycle.c: In function 'ngx_start_worker_processes' ...

  10. 使用Docker遇到的基本命令及问题小结

    当遇到Cannot connect to the Docker daemon. Is the docker daemon running on this host?导致Docker无法启动时,重启Do ...