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...、逻辑运算符的更多相关文章

  1. Python开发基础-Day5-字符编码、文件处理和函数基础(草稿)

    字符编码 为什么要有字符编码? 字符编码是为了让计算机能识别我们人写的字符,因为计算机只认识高低电平,也就是二进制数"0","1". 一个文件用什么编码方式存储 ...

  2. python开发基础01-字符串操作方法汇总

    字符串 Python对字符串的处理内置了很多高效的函数,非常方便功能很强大. "hello world" 字符串七种常用功能: 连接和合并 + join 移除空白  strip 分 ...

  3. python 格式话-占位符

    格式化输出:name = qjage = 30job = itsalary = 6000例1:字符串拼接方法,不建议,因为会在内存中开辟多块内存空间. info = '''---------- inf ...

  4. Python语言基础06-字符串和常用数据结构

    本文收录在Python从入门到精通系列文章系列 1. 使用字符串 第二次世界大战促使了现代电子计算机的诞生,最初计算机被应用于导弹弹道的计算,而在计算机诞生后的很多年时间里,计算机处理的信息基本上都是 ...

  5. python开发基础02-字符串操作方法练习题

    1.执行 Python 脚本的两种方式 python解释器 py文件  #!/usr/bin/env python 进入python解释器,便捷命令并执行 pycharm或其他pythonIDE sh ...

  6. 关于python中format占位符中的 {!} 参数

    在看celery的时候,发现里面有这么一句 print('Request: {0!r}'.format(self.request)) 关于里面的{0!r}是什么意思翻了一下文档. 文档里是这么描述的 ...

  7. Python基础(条件判断,循环,占位符等)

    Python 自动化 系统开发用的语言和自动化脚本可以不同 学习peython可用于: 网路爬虫,数据分,web开发,人工智能,自动化运维,自动化测试,嵌入式,黑客 第三方库比较全 脚本语言:功能单一 ...

  8. python基础入门--input标签、变量、数字类型、列表、字符串、字典、索引值、bool值、占位符格式输出

    # 在python3 中: # nian=input('>>:') #请输入什么类型的值,都成字符串类型# print(type(nian)) # a = 2**64# print(typ ...

  9. python基础之二:占位符、格式化输出、while else 、逻辑运算

    1.占位符和格式化输出 示例代码 #格式化输出 # % s d # name = input('请输入姓名') # age = input('请输入年龄') # height = input('请输入 ...

随机推荐

  1. java中多种方式解析xml

    第一种:DOM.DOM的全称是Document Object Model,也即文档对象模型.在应用程序中,基于DOM的XML分析器将一个XML文档转换成一个对象模型的集合(通常称DOM树),应用程序正 ...

  2. ThinkPHP5.1x 中间件实现原理

    ThinkPHP5.1x的中间件,其核心还是闭包函数的应用,来实现“责任链”模式: 模拟代码: <?php //模拟的控制器 class Controller { public function ...

  3. windows服务器装macos虚拟机(vmware)系统

    VMware14安装黑苹果macOS10.13流程 一.准备工具 VMware Workstation 14.1.2 Pro macOS High Sierra 10.13.iso格式或.cdr格式( ...

  4. linux文件管理--压缩打包

    目录 linux文件管理--压缩打包 1.压缩打包介绍 2.gzip压缩工具 3.zip压缩工具 注意: 4.tar压缩工具 5.tar生产案例实践 linux文件管理--压缩打包 1.压缩打包介绍 ...

  5. python socket的长连接和短连接

    前言 socket中意为插座,属于进程间通信的一种方式.socket库隐藏了底层,让我们更好的专注于逻辑.如果短连接和长连接两概率没搞明白,会被坑的爬不起来. 短连接 一次完整的传输过程,发送方输出流 ...

  6. 四、yml文件的写法

    1.创建一个新的工程 注意:只有properties文件,没有包含yaml文件 2.创建一个yml文件 全局配置配置文件,文件名是固定的application 作用:修改SpringBoot自动配置的 ...

  7. 运用pool进程池启动大量子进程

    # Pool进程池类 from multiprocessing import Pool import os import time import random def run(index): prin ...

  8. Elasticsearch 分布式文档存储

    shard = hash(routing) % number_of_primary_shards决定文档在哪个分片上,routing 是一个可变值,默认是文档的 _id ,也可以设置成一个自定义的值. ...

  9. jQuery 菜单 水平菜单的实现

    html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...

  10. springbootboot 语句

    -- ------------------------------ Table structure for `user`-- ----------------------------DROP TABL ...