一,while 循环

1. 循环. while循环    while 条件:        代码块(循环体)    执行流程:        1. 判断条件是否为真. 如果真. 执行代码块        2. 再次判断条件是否为真......        3. 当条件为假.执行else 跳出循环. 循环结束例
count=1while count<3:    print("嘿嘿")    count=count+1

while True:    s=input("输入密码:")    if s=="5":       break    print ("输出密码"+s)'''# while True:#     s=input("输入密码:")#     if s=="5":#        break##     if "6"in s:#         print("okle")#         continue#     print("输出密码" + s)# count=1# sum=0# while count<=100:#     sum=sum+count#     count=count+1# print(sum)# count=1# while count<=100:#     if count%2 !=0:#         print (count)#     count=count+1# count=1# while count<=100:#     if count % 2 == 0:#         print(count)#     count+=1   #count= count +1
# 1+2+3+4+5+6+7+8....+100 = ?# count = 1# # 准备一个变量# sum = 0# while count <= 100:#     # 累加到sum中#     sum = sum + count   # 把sum中的值(之前运算的结果)和当前数的数相加#     count = count + 1# print(sum)

# 输出1-100所有的奇数.# count = 1# while count <= 100:##     if count % 2 != 0:#         print(count)##     count = count + 1
二,格式化输出    %s: 字符串的占位符, 可以放置任何内容(数字)    %d: 数字的占位符例
# name = input("请输入名字:")# age = input("请输入你的年龄:")# hobby = input("输入你的爱好:")# gender = input("请输入你的性别:")## # print(name+"今年"+age+"岁, 是一个老头, 爱好是"+hobby+", 性别:"+gender)# #  %s : 表示字符串的占位符# print("%s今年%s岁, 是一个老头, 爱好是%s, 性别:%s" % (name, age, hobby, gender))

# a = 108# s = "梁山水泊有%d个牛B的任务" % (a)# print(s)

# name = "a"# print("%s已经喜欢了沙河%%2的女生" % name)  # 如果字符串中有了占位符. 那么后面的所有的%都是占位. 需要转义print("b很色.喜欢了昌平%5的女生") # 这句话中没有占位符. %还是%

三, 运算符    逻辑运算:    and  并且的意思. 左右两端的值必须都是真. 运算结果才是真    or   或者的意思. 左右两端有一个是真的. 结果就是真. 全部是假. 结果才能是假    not  非的意思. 原来是假. 现在是真.  非真即假, 非假既真break   结束循环. 停止当前本层循环continue  结束当前本次循环. 继续执行下一次循环例
# 计算机常用的数据# print(2**0) # 1# print(2**1) #2# print(2**2)# print(2**3)# print(2**4)# print(2**5)# print(2**6)# print(2**7)# print(2**8)# print(2**9)# print(2**10)

# 赋值运算.# a = 10# a += 20     # a = a + 20# print(a)

# print(not not not not not not False)

# and or not同时存在. 先算括号, 然后算not, 然后算and , 最后算or# print(3>4 or 4<3  and  1==1) # False## print(1 < 2  and  3 < 4 or 1>2  )# 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)# print(not  2 > 1  and 3 < 4  or 4 > 5  and 2 > 1  and 9 > 8  or 7 < 6)

# x or y 如果x==0 那么就是y, 否则是x# print(1 or 2)   # 1# print(2 or 3)   # 2# print(0 or 3)   # 3# print(0 or 4)   # 4

# print(0 or 1 or 3 or 0 or 5)    ## print(1 and 2)  # 2# print(2 and 0)  # 0# print(0 and 3)  # 0# print(0 and 4)  # 0print(0 or 4 and  3 or 7 or 9 and 6)

# print(2 > 3 and 3)      # false相当于0# print(2 < 1 and 4 > 6 or 3 and 4 > 5 or 6)四,while...else例
count  = 1while count  <= 10:    print( count)    count = count + 1    if count == 5:        break   # 彻底停止循环. 不会执行后面的elseelse:   # while条件不成立的时候执行    print("这里是else")


while 循环,格式化输出,运算符(not,and,or)的更多相关文章

  1. while循环 格式化输出 运算符 编码

    一.while循环 1.基本结构 while 条件:            循环体   流程: 判断条件是否为真. 如果真, 执行代码块. 然后再次判断条件是否为真 .如果真继续执行代码块....  ...

  2. DAY2---Python---While循环,格式化输出,运算符,编码

    一.while循环 while 条件: 代码块(循环体) 流程:判断条件是否为真,如果是真,执行代码块.然后再次判断条件是否为真,如果为真继续执行代码块... 直到条件变成了假,退出循环 #死循环:永 ...

  3. python之while循环/格式化输出/运算符/初始编码/成员变量

    一.主要内容:1.while 循环 (难点)while 条件: 循环体 break: 直接跳出循环continue:停止当前本次循环,继续执行下一次循环.不会中断循环能让循环退出:(1)break ( ...

  4. python---02.while循环 格式化输出 运算符 编码

    一.while循环语句 1.while 条件:(如果条件是真, 则直接执⾏循环体. 然后再次判断条件. 直到条件是假. 停⽌循环) 循环体(break  continue) 2. break: 立刻跳 ...

  5. python全栈 流程控制;while 循环 格式化输出 运算符 及编码

    python全栈开发 1循环 2break和continue的区别 3格式化输出 4运算符 5编码 一.流程控制while循环 while条件: 代码块(循环体) 1.死循环; while True; ...

  6. 第二天-while循环 格式化输出 运算符 编码

    一.while循环 while 条件: 语句块(循环体)     #判断条件是否成立,若成立执行循环体,然后再次判断条件...直到不满足跳出循环 else: 当条件不成立的时候执行这里,和break没 ...

  7. while循环,格式化输出,运算符

      1.while循环 1.while 基本机构: while 条件: 循环体 执行流程: 当条件成立时为真,执行循环体. 再次判断条件是否成立,如果成立再次执行. 当判断条件结果为假时,跳出循环,本 ...

  8. python中的while循环,格式化输出,运算符,编码

    一.while循环 1.1语法 while 条件: 代码块(循环体) else: 当上面的条件为假的的时候,才会执行. 执行顺序:先判断条件是否为真,如果是真的,执行循环体,再次判断条件,直到条件不成 ...

  9. 记录我的 python 学习历程-Day02-while 循环/格式化输出/运算符/编码的初识

    一.流程控制之--while 循环 循环就是重复做同一件事,它可以终止当前循环,也可以跳出这一次循环,继续下一次循环. 基本结构(基本循环) while 条件: 循环体 示例 # 这是一个模拟音乐循环 ...

随机推荐

  1. python list 转换为str

    xiaoquInfo = ['暂无参考均价', '中仪花园海伦堡', '113.403781', '22.540973', '2008年建成', '塔楼', '2元/平米/月', '海伦堡物业', ' ...

  2. Modelsim使用流程---基于TCL命令的仿真

    Modelsim使用流程---基于TCL命令的仿真 本文使用的Modelsim版本为Modelsim SE-64 10.1.c 1.File -> new -> Project 2.添加或 ...

  3. 阅读《7 Series FPGAs GTX/GTH Transceivers User Guide》

    阅读<7 Series FPGAs GTX/GTH Transceivers User Guide> 1.GTX在XC7K325T芯片内的排列 2.参考时钟的配置 在GTXE2_COMMO ...

  4. Tribon/AM 数据库名字的含义

    收集在这里备用 数据库名 Tribon环境变量 内容描述 船体型线数据库 SB_CGDB 船体外型信息 型表面,船体曲线,板缝 船体结构数据库 SB_OGDB 船体模型信息 板材数据库 SB_PLDB ...

  5. modbus tcp 入门详解

    Modbus tcp 格式说明 通讯机制 附C#测试工具用于学习,测试   前言: 之前的博客介绍了如何用C#来读写modbus tcp服务器的数据,文章:http://www.cnblogs.com ...

  6. 将mongo设置为windows的服务

    原文链接 https://mp.weixin.qq.com/s/rmWcvjZFJb3z_5M8UPWAPQ PHP的mongo扩展: 首先 下载一个PHP的mongo扩展, 地址:http://do ...

  7. spring 基本配置学习

    1.bean的方式说明 作用:    用于配置对象让spring来创建的. 默认情况下它调用的是类中的无参构造函数.如果没有无参构造函数则不能创建成功. 属性: id:给对象在容器中提供一个唯一标识. ...

  8. 【git】之push异常

    Push rejected: Push to origin/master was rejected 打开git shell面板 $ git pull origin master --allow-unr ...

  9. LeetCode——3. Longest Substring Without Repeating Characters

    一.题目链接:https://leetcode.com/problems/longest-substring-without-repeating-characters 二.题目大意: 给定一个字符串, ...

  10. Mongod服务器安装

    第一步下载mongodb 目前最新版本:3.4.4 第二步安装vc_redist.x64 服务器安装可能会需要到,如果没有出现以下错误不需要安装 --------------------------- ...