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('请输入 ...
随机推荐
- js-xlsx sheet_to_json 读取小数位数变多
read as string . 例如:2.85 读取后变成 2.84999999999999999 这种. 以字符串形式读取. XLSX.utils.sheet_to_json(workbook.S ...
- multiprocessing的Process类的简单使用
''' 跨平台的进程创建模块(multiprocessing) 支持跨平台 :window/linux multiprocessing提供一个Process类来代表一个进程对象 ''' from mu ...
- PAT甲级【2019年3月考题】——A1157 Anniversary【25】
Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebrat ...
- [转]Linux Shell编程入门
转自:http://www.cnblogs.com/suyang/archive/2008/05/18/1201990.html 从程序员的角度来看, Shell本身是一种用C语言编写的程序,从用户的 ...
- NULL合并操作符??
参考官方手册: /** * NULL合并操作符 ?? */ // $a, $b, $c都未声明和定义 var_dump($a??$b??$c); // NULL // $a为数组,$b为100,$c为 ...
- spring 事物(一)—— 事物详解
事务概念回顾 什么是事务? 事务是逻辑上的一组操作,要么都执行,要么都不执行. 事物的特性(ACID): 事务的特性 原子性: 事务是最小的执行单位,不允许分割.事务的原子性确保动作要么全部完成,要么 ...
- 如何从零搭建一个webpack+react+redux+react-redux的开发环境一入门
阅读本文章的时候,你要有一定的基础知识储备,简单的es6知识,模块化思想知识,js基础知识,node基础知识,react等 首先执行npm init,此时我的文件叫case; 下面安装一些需要的npm ...
- 使用while循环实现菜单
- Ansible--01 ansible基础 Ansible-ad- hoc
目录 自动化运维工具-Ansible基础 自动化运维的含义 Ansible 基础及安装 Ansible的架构 Ansible的执行流程 ansible配置文件 ansible Inventory(主机 ...
- Kaggle数据集下载
Kaggle数据集下载步骤: 安装Kaggle库: 注册Kaggle账户: 找到数据集,接受rules: 在My Account>>API中,点击Create New API Token, ...