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. Prometheus 安装与配置

    下载Prometheus https://prometheus.io/download/ wget https://github.com/prometheus/prometheus/releases/ ...

  2. 美团2018年CodeM大赛-资格赛

    https://www.nowcoder.com/acm/contest/138#question A.下单 水题…… B.可乐 题意:求期望 代码: #include<iostream> ...

  3. POJ 3020:Antenna Placement(无向二分图的最小路径覆盖)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6334   Accepted: 3125 ...

  4. MVC的实体模型写在类库,为什么被其他类库调用时,用不了模型的表?

    一,很简单,由于第一次添加实体模型时,VS会自动帮你添加引用System.Data.Entity到当前类库,如下图示: 二,而手动添加的类库并不存在这个引用,则及时你引用了当前的实体模型的类库,却使用 ...

  5. 爬虫示例--requests-module

    reuqests_test .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { ...

  6. reduce 好东西

    reduce()方法可以搞定的东西,for循环,或者forEach方法有时候也可以搞定,那为啥要用reduce()?这个问题,之前我也想过,要说原因还真找不到,唯一能找到的是:通往成功的道路有很多,但 ...

  7. svn解决方案

    1.svn回退 revert to this version 2.不同svn路径拉倒一个本地文件夹,报错"已经指向不同的url工作副本":  删除文件夹中的.svn文件夹 3.sv ...

  8. numpy.unique

    Find the unique elements of an array. Returns the sorted unique elements of an array. There are thre ...

  9. Django框架的学习

    目前 Django 1.6.x 以上版本已经完全兼容 Python 3.x. 1. 指定django版本的安装 pip install django =1.11

  10. vim常用的骚操作

    1.设置~/.vimrc syntax on    支持语法高亮 set nu          显示行号set nonu      不显示行号 set ai           设置自动缩进 set ...