Python学习日记:day2
1、格式化输出
name = input("请输入你的名字:") age =input("请输入你的年龄:") job =input("请输入你的工作:") hobbie =input("请输入你的爱好:") msg ='''--------------info of %s-------------- name : %s age : %d job : %s hobbie : %s --------------end--------------''' %(name,name,int(age),job,hobbie) print(msg)
#格式化输出1: name = input('请输入姓名') age = input('请输入年龄身高') height = input('请输入身高') msg="我叫%s,今年%s,升高%s,"%(name,age,height)
想要在格式化输出中单纯的输出%,加%%。
%占位符,s,字符串,d digit数字
%%只是单纯的显示百分号%。
name = input('请输入姓名') age = input('请输入年龄身高') height = input('请输入身高') msg="我叫%s,今年%s,升高%s,我的学习进度为3%%" %(name,age,height)
2、while else
与其它语言else 一般只与if 搭配不同,在Python 中还有个while ...else 语句
while 后面的else 作用是指,当while 循环正常执行完,中间没有被break 中止的话,就会执行else后面的语句
count = 0 while count <= 5 : count += 1 print("Loop",count) else: print("循环正常执行完啦") print("-----out of while loop ------")
输出:
如果执行过程中被break啦,就不会执行else的语句
count = 0 while count <= 5 : count += 1 if count == 3:break print("Loop",count) else: print("循环正常执行完啦") print("-----out of while loop ------")
输出:
3、初始编码
(1)最早的密码本-ASCII码,最早是七位,涵盖了英文字母,大小写,特殊字符,数字。
预留1位,以备拓展,所以ASCII是8位。
(2)ASCII 只能表示256种可能,太少,创办为万国码。Unicode。
Unicode开始用16位表示一个字符,不行。升级为32位表示一个字符。
但是Unicode表示一个字符太长,升级为utf-8、utf-16、utf-32
8位 =1字节bytes
utf-8 一个字符最少用八位来表示,英文用八位,欧洲的文字用16位来表示,中文用24位来表示
utf-16 一个字符最少用16位来表示。
(3)GBK 中国人自己发明的。一个字节用两个字节 16位去表示。
1bit(位)
8 bit=1bytes
1 byte 1024byte=1KB
1kb 1024kb =1MB
1MB 1024MB= 1GB
1GB 1024GB =1TB
4、基本运算符
(1)
逻辑运算
#and or not
#优先级,()>nor>and>or print(2>1 and 1<4)true print (2>1and 1<4 or 2<3 and 9>6 or 2>4) 1,3>4 or 4<3 and 1==1 2,1 < 2 and 3 < 4 or 1>2 3,2 > 1 and 3 < 4 or 4 > 5 and 2 < 1 4,1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8 5,1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 6,not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
'''
1,F or F False
2,T or F True
3,T or F True
4,F or F or F False
5,f or f or f False
6,f or f or f False
'''
#x or y x 为非零(True),则返回x #x and y x 为非零(True),则返回y print (0 and 2)#0 3<2 思考题 print(1>2 and 3 or 4 and )
#数字与布尔值的转换 #ps:int------->bool 非零转换成bool 为true 0转换成bool值为false。 print (bool(2)) true print (bool(2-)) true print (bool(0)) false #bool------> int
最新文章
- SubSonic3.0使用例子
- ASP.NET中的缓存机制
- nagios二次开发(一)---开发思想
- 【转】TableLayout(表格布局)
- ES6还是ES2015?
- <;八>;面向对象分析之UML核心元素之分析类
- mysql修改表、字段、库的字符集
- ABI Management
- Spring的StringUtils工具类
- cocos2d-x -------之笔记篇 环境的安装
- Openlays 3 绘制基本图形
- javascript中的window.open()被浏览器拦截
- js+画曲线和圆 并限制圆的渲染范围
- 删除Docker镜像
- HTTP各种特性
- kubernete 数据库 etcd
- 【Babble】批量学习与增量学习、稳定性与可塑性矛盾的乱想
- ElasticSearch入门 第一篇:Windows下安装ElasticSearch
- Python自动化必备发送邮件报告脚本详解
- 快速滑动时 `cellForRow` 的调用次数