python_format格式化输出、while else、逻辑运算符、编码初识
1、格式化输出 。%d %s
- 格式化输出:% 占位符,d 表示替换整型数,s表示要替换字符串。
- name = input('请输入名字:')
- age = input('请输入年龄:')
- sex = input('请输入性别:')
- msg = '我的名字是' + name + '我的年龄是' + age + '我的性别是' + sex
- print(msg)
- msg = '''
- ------------ info of Alex Li -----------
- Name : Alex Li
- Age : 22
- job : Teacher
- Hobbie: girl
- ------------- end -----------------
- '''
- print(msg)
d 表示替换整型数,s表示要替换字符串。
- name = input("请输入姓名:")
- age = int(input("请输入年龄:"))
- job = input("请输入工作:")
- hobby = input("请输入爱好:")
- msg = '''
- ------------ info of %s -----------
- Name : %s
- Age : %d
- job : %s
- Hobbie: %s
- ------------- end -----------------
- ''' % (name, name, age, job, hobby)
- print(msg)
- dic = {
- 'name': '老男孩',
- 'age': 58,
- 'job': 'boss',
- 'hobby': 'money',
- }
- msg = '''
- ------------ info of %(name)s -----------
- Name : %(name)s
- Age : %(age)d
- job : %(job)s
- Hobbie: %(hobby)s
- ------------- end -----------------
- ''' % dic
- print(msg)
在格式化输出中,需要表示单纯的百分号%,要用双百分号%%表示。
- msg = '我叫%s,今年%d,学习进度2%%.' % ('爽妹儿',18)
- print(msg)
2、while else
while else 中,当while的循环被break打断时,不走else程序。
- count = 0
- while count <= 5:
- count += 1
- print('loop',count)
- if count == 4:
- break
- else:
- print('循环正常执行完啦')
- print("-----out of while loop ------")
3、运算符
1、逻辑符前后都是比较运算
优先级概念:
() > not > and > or
同一优先级从左到右以此计算。
- print(2 > 1 and 3 < 4 or 8 < 10 and 4 > 5)
- print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)
- print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8)
- print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6)
2、逻辑符前后都是数字
or
x or y , if x Ture,Return x , else Return y .
x !=0,x is Ture .
- print(3 or 5)
- print(2 or 5)
- print(0 or 5)
- print(-4 or 5)
- print(1 or 3 or 0)
- print(1 or 3 or 4 or 0)
and
and 的规则与or完全相反。
- print(3 and 5)
- print(1 > 2 and 3 or 4)
数字与bool值转化
- int ---> bool 非零 True ,零 False
bool---> int True 1, False 0
- print(bool(100))
- print(bool(0))
4、编码初识
谍战片:滴滴滴 滴滴 高低电平,0101010
电脑文件的存储,与文件的传输。010101010
初级密码本:
ASCII码 字母、数字、特殊符号。
0000 0001 8位 == 一个字节,一个字节表示一个字符。
字符:组成内容的最小单元。
abc a b c
中国 中 国
万国码:unicode
创建初期 16位,两个字节表示一个字符。
a :01100001 01100001
中:01100011 01100001
升级后 32位,四个字节表示一个字符。
a :01100001 01100001 01100001 01100001
中:01100011 01100001 01100011 01100001
浪费资源。(硬盘,流量等)
对Unicode升级:utf-8
utf-8:最少用8位数表示一个字符。
a:01100001(字母用1个字节表示。)
欧洲文字:01100001 01100001(欧洲用2个字节表示。)
亚洲文字——中:01100001 01100001 01100001 (欧洲用3个字节表示。)
utf-16:最少用16位表示一个字符。
gbk:国家标准。
a : 01100001
中: 01100001 01100001
8位组成一个byte
1024bytes 1kb
1024kb 1MB
1024MB 1GB
1024GB 1TB
python_format格式化输出、while else、逻辑运算符、编码初识的更多相关文章
- while循环、格式化输出、运算符和编码初识
while循环 1. while循环的结构 while 条件: 执行语句1 执行语句2 i = 0 while i < 10: print(i) i += 1 运行结果 0 1 2 3 4 5 ...
- python 基础(while 循环、格式化输出、运算符、编码初识)
while循环 break 终止当前循环 count = 1 while count < 3: print(count) count += 1 break # while循环中一旦代码执行到br ...
- 2.Python基础认识(格式化输出,while语句,运算符,编码,单位转化)
Python基础认识 1.字符串的格式化初识及占位符的简单应用 字符串的格式化 按照既定的要求进行有规定排版的一种输出方式. #我们想要输出的格式如下: ----------------------- ...
- day02 循环、格式化输出、运算符、编码
01 昨日内容回顾 python2x python3x区别: python2x:源码重复,不规范. python3x:源码规范,优美,清晰,简单. 编译型:将代码一次性全部转化成字节码. 代表语言:C ...
- python全栈 流程控制;while 循环 格式化输出 运算符 及编码
python全栈开发 1循环 2break和continue的区别 3格式化输出 4运算符 5编码 一.流程控制while循环 while条件: 代码块(循环体) 1.死循环; while True; ...
- 记录我的 python 学习历程-Day02-while 循环/格式化输出/运算符/编码的初识
一.流程控制之--while 循环 循环就是重复做同一件事,它可以终止当前循环,也可以跳出这一次循环,继续下一次循环. 基本结构(基本循环) while 条件: 循环体 示例 # 这是一个模拟音乐循环 ...
- while循环,格式化输出,运算符及编码初识
一.while循环 1.基本循环(死循环) while 条件: 循环体 2.使用while计数 count = 0 # 数字里面非零的都为True while True: count = count ...
- day 02 while 循环 格式化输出 运算符 and or not - 编码的初识
while 循环 while 条件: 循环体 循环如何终止? 改变条件. flag = Truewhile flag: print('狼的诱惑') print('我们不一样') ...
- python -- while循环,格式化输出,运算符,初识编码
一.while循环 1.语法 while 条件: 循环体(结果) 如果条件为真,则直接执行结果),然后再次判断条件,知道条件为假,停止循环. while True: print('你是谁呢') 退 ...
随机推荐
- 监控MySQL或Web服务是否正常
在工作中,我们往往利用脚本定时监控本地.远端数据库服务端或Web服务是否运行正常,例如:负载高.cup高.连接数满了等.... 方法一:根据端口 本地:netstat/ss/lsof ① nets ...
- JavaSE: SuppressWarnings[转]
在java编译过程中会出现很多警告,有很多是安全的,但是每次编译有很多警告影响我们对error的过滤和修改,我们可以在代码中加上 @SuppressWarnings(“XXXX”) 来解决 例如:@S ...
- layui中,同一个页面动态加载table数据表格
效果图: 前端代码: <div class="layui-fluid" id="record-user" hidden="hidden" ...
- LeetCode算法题-Merge Sorted Array(Java实现)
这是悦乐书的第161次更新,第163篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第20题(顺位题号是88).给定两个排序的整数数组nums1和nums2,将nums2中 ...
- js中split()方法得到的数组长度
js 中split(",")方法通过 ”,“ 分割字符串, 如果字符串中没有 “,” , 返回的是字符串本身 var str = “abc”://分隔符个数为0 var newSt ...
- 2.04-proxy-handler
import urllib.request def create_proxy_handler(): url = "https://blog.csdn.net/m0_37499059/arti ...
- (二 -4) 天猫精灵接入Home Assistant-自动发现Mqtt设备--传感器系列
https://www.home-assistant.io/blog/2015/10/11/measure-temperature-with-esp8266-and-report-to-mqtt/ 最 ...
- flask_socket_io中报错RuntimeError: You need to use the eventlet server. See the Deployment section of the documentation for more information.的解决办法
最新的flask_socketio 使用的是python-socketio 如果在包中安装了gevent或evenlet,在服务器上使用时,就会报错 RuntimeError: You need to ...
- Spring Security(二十八):9.4 Authentication in a Web Application
Now let’s explore the situation where you are using Spring Security in a web application (without we ...
- matlab中fix函数,floor函数,ceil函数
1)fix(n)的意义是取小于n的整数(是向零点舍入的意思是往零的方向上靠),这是一类应用在整数取值上的函数,就如同以前我们所研究的求整问题,例如,fix(pi)=3;fix(3.5)=3;fix(- ...