02、python的基础-->占位符、while...else...、逻辑运算符
1、%s、%d格式化输出程序(%占位符,s字符串,d数字)
- 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)
注:如果单纯的想在格式化输出%,需要用2个%,如:30%%即可。
2、while...else 的使用
- count = 0
- while count <= 5 :
- count += 1
- if count == 3:break #当程序遇到break,自动跳出循环
- print("Loop",count)
- else:
- print("循环正常执行完啦")
- print("-----out of while loop ------")
3、逻辑运算符
- #and or not
- #优先级,()> not > and > or
- print(2 > 1 and 1 < 4)
- print(2 > 1 and 1 < 4 or 2 < 3 and 9 > 6 or 2 < 4 and 3 < 2)
- T or T or F
- T or F
- print(3>4 or 4<3 and 1==1) # F
- print(1 < 2 and 3 < 4 or 1>2) # T
- print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # T
- print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # F
- print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F
- print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F
- #ps int ----> bool 非零转换成bool True 0 转换成bool 是False
- print(bool(2))
- print(bool(-2))
- print(bool(0))
- #bool --->int
- print(int(True)) #
- print(int(False)) #
- '''x or y x True,则返回x'''
- print(1 or 2) #
- print(3 or 2) #
- print(0 or 2) #
- print(0 or 100) #
- print(2 or 100 or 3 or 4) #
- print(0 or 4 and 3 or 2) #
注:and跟or运算结果相反
4、面试题
- '''x and y x True,则返回y'''
- print(1 and 2) #
- print(0 and 2) #
- print(2 or 1 < 3) #
- print(3 > 1 or 2 and 2) # Ture
02、python的基础-->占位符、while...else...、逻辑运算符的更多相关文章
- Python开发基础-Day5-字符编码、文件处理和函数基础(草稿)
字符编码 为什么要有字符编码? 字符编码是为了让计算机能识别我们人写的字符,因为计算机只认识高低电平,也就是二进制数"0","1". 一个文件用什么编码方式存储 ...
- python开发基础01-字符串操作方法汇总
字符串 Python对字符串的处理内置了很多高效的函数,非常方便功能很强大. "hello world" 字符串七种常用功能: 连接和合并 + join 移除空白 strip 分 ...
- python 格式话-占位符
格式化输出:name = qjage = 30job = itsalary = 6000例1:字符串拼接方法,不建议,因为会在内存中开辟多块内存空间. info = '''---------- inf ...
- Python语言基础06-字符串和常用数据结构
本文收录在Python从入门到精通系列文章系列 1. 使用字符串 第二次世界大战促使了现代电子计算机的诞生,最初计算机被应用于导弹弹道的计算,而在计算机诞生后的很多年时间里,计算机处理的信息基本上都是 ...
- python开发基础02-字符串操作方法练习题
1.执行 Python 脚本的两种方式 python解释器 py文件 #!/usr/bin/env python 进入python解释器,便捷命令并执行 pycharm或其他pythonIDE sh ...
- 关于python中format占位符中的 {!} 参数
在看celery的时候,发现里面有这么一句 print('Request: {0!r}'.format(self.request)) 关于里面的{0!r}是什么意思翻了一下文档. 文档里是这么描述的 ...
- Python基础(条件判断,循环,占位符等)
Python 自动化 系统开发用的语言和自动化脚本可以不同 学习peython可用于: 网路爬虫,数据分,web开发,人工智能,自动化运维,自动化测试,嵌入式,黑客 第三方库比较全 脚本语言:功能单一 ...
- python基础入门--input标签、变量、数字类型、列表、字符串、字典、索引值、bool值、占位符格式输出
# 在python3 中: # nian=input('>>:') #请输入什么类型的值,都成字符串类型# print(type(nian)) # a = 2**64# print(typ ...
- python基础之二:占位符、格式化输出、while else 、逻辑运算
1.占位符和格式化输出 示例代码 #格式化输出 # % s d # name = input('请输入姓名') # age = input('请输入年龄') # height = input('请输入 ...
随机推荐
- HDU 5183 Negative and Positive (NP) (手写哈希)
题目链接:HDU 5183 Problem Description When given an array \((a_0,a_1,a_2,⋯a_{n−1})\) and an integer \(K\ ...
- 面试题40:最小(大)的K个数
剑指offer40题,同时这也是面试高发题目 2019.4 蚂蚁金服问道:求1000万个数据中的前K个数. 思路: 1.直接上排序算法,然后我们就取排好顺序的前K个即可.但是单考虑快排,时间复杂度也要 ...
- VMware Workstation Pro 无法在Windows 上运行 检查可在Windows上运行的此应用的更新版
1.问题描述 2.排查原因 国庆节后微软推送了一个新的更新补丁,更新之后发现VMware无法打开(未更新前正常). 3.解决方案 3.1卸载微软更新补丁 Windows 10的安全更新难以被彻底规避, ...
- 转 Xshell ssh长时间连接不掉线设置
1.Xshell客户端设置 2.服务器设置 vi /etc/ssh/sshd_config 把ClientAliveInterval 0和ClientAliveCountMax 3前的井号去掉,并把C ...
- spring boot 多环境(dev、test、prod)配置文件---命令行切换
properties配置格式 在Spring boot 中多环境配置文件名需要满足application-{profile}.properties的格式,其中{profile}对于你的环境标识,比如: ...
- js数据处理-----数据拷贝
一.理解深拷贝与浅拷贝 如下代码,把 a 的值赋给 b ,修改 b 的值会直接修改到 a 的值,这叫浅拷贝.(其实他们修改的是同一个对象) var a = [1,2,3,4,5]; var b ...
- Skimap_ros 利用RGBD创建Octomap(一)
1. 奥比中光astra RGBD相机安装 1.1 安装依赖 $ sudo apt-get install build-essential freeglut3 freeglut3-dev 1.2 检查 ...
- go语言从例子开始之Example8.数组
在 Go 中,数组 是一个固定长度的数列. package main import "fmt" func main() { 这里我们创建了一个数组 a 来存放刚好 5 个 int. ...
- Educational Codeforces Round 69 E - Culture Code (最短路计数+线段树优化建图)
题意:有n个空心物品,每个物品有外部体积outi和内部体积ini,如果ini>outj,那么j就可以套在i里面.现在我们要选出n个物品的一个子集,这个子集内的k个物品全部套在一起,且剩下的物品都 ...
- 错误描述:fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "stdafx.h"”?(转)
错误分析: 此错误发生的原因是编译器在寻找预编译指示头文件(默认#include "stdafx.h")时,文件未预期结束.没有找到预编译指示信息的头文件"stdafx. ...