2.while循环 编码的初识,逻辑运算符 格式化输出
while循环
循环
while True: # while 是关键字 条件
print('精忠报国')
print('团结就是力量')
print('北京欢迎你')
print('葫芦爷爷救娃娃')
3 > 2 条件控制循环的终止 和次数
num = 3
while num >= 1:
print(num)
num = num - 1
while True:
print(1)
while True:
print(123)
break
print(234)
break 作用:终止当前这个循环
while True:
print(1)
continue
print(2)
continue 跳出本次循环,继续下次循环
本人理解 -- continue就是伪装成了循环体中的最后一行
print(456)
while True:
print(1)
print(2)
print(123)
while True:
print(1)
print(2)
break
print(3)
num = 5
while num > 4:
print(1)
print(2)
num = num - 1
break
else:
print(3)
num = 5
while num > 4:
print(1)
print(2)
num = num - 1
print(3)
格式化
"""
------------------- info ----------------------
name: xxx
age: xxx
sex : xxx
job: xxx
hobby: xxx
------------------- end ------------------------
"""
# a = "------------------- info ----------------------"
# b = "name:"
# c = "age:"
# d = "sex:"
# e = "job:"
# f = "hobby:"
# g = "------------------- end ------------------------"
#
# name = input('name:')
# age = input('age:')
# sex = input('sex:')
# job = input('job:')
# hobby = input('hobby:')
#
# print(a + '\n' + b + name + '\n' + c + age + '\n' + d + sex + '\n' + e + job + '\n'
# + f + hobby + '\n' + g
# )
# name = input("name:")
# age = input("age:")
# sex = input("sex:")
# job = input("job:")
# hobby = input("hobby:")
# print(msg%(input("name:"),input("age:"),input("sex:"),input("job:"),input("hobby:")))
# 字符串格式化的时候 不能少 不能多 (占的数量和填充的数量要一致)
# 填充的时候 内容和占的位置是要一一对应的
"""
------------------- info ----------------------
name: %s
age: %s
sex : %s
job: %s
hobby: %s
------------------- end ------------------------
"""
# %s ,%d, %%
# msg = '%s,学习进度5%%'
# print(msg%(input("name:")))
# %s -- 占字符串的位置
# %d -- 占整型的位置
# %% -- 转义(把占位转换成普通的%号)
# name = input("name")
# print(f"alex{name},{'aaa'}")
# f字符串拼接 -- 3.6版本及以上才能使用
msg = '''
------------------- info ----------------------
name: %s
age: %s
sex : %s
job: %s
hobby: %s
------------------- end ------------------------
'''
print(msg%('alex','20','nan','it','cnb'))
msg = f'''
------------------- info ----------------------
name: {input("name:")}
age: {input("age:")}
sex : {input("sex:")}
job: {input("job:")}
hobby: {input("hobby:")}
------------------- end ------------------------
'''
print(msg)
运算符
赋值运算(**)
a = 1
a += 1 # a = a + 1
print(a)
a -= 1 # a = a - 1
print(a)
a *= 1 # a = a * 1
print(a)
a /= 1 # a = a / 1
a **= 1 # a = a ** 1
a %= 1 # a = a % 1
算数运算(*)
+ - * /
** 幂
print(2 ** 4)
# // 整除
print(5 // 2)
% 取余(模)
print(5 % 2)
逻辑运算(***)
and 两个都为真,取右边的,有一个假的,取假的,两边都为假,取左边的
or 两个都为真,取左边的,有一个真的,取真的,两边都是假,取右边的。
and (与) -- 和
or (或)
not (非) -- 不是
1 and 0 # and是两边都是真的时候才是真,只要有一边是假就取假
0 and 1
print(1 and 9) #and 运算 两边都是真的时候取and后边的内容
print(False and 0) #and 运算 两边都是假的时候取and前边的内容
print(3 > 2 and 9) 3>2 视为一个整体来看
or
print(1 or 0) # 只要有一个是真就取真
print(0 or 1)
print(1 or 4) # or 两个都是真的时候,取or前面的内容
print(False or 0) # or 两个都是假的时候,取or后面的内容
print(3>2 or 4)
not
() > not > and > or
print(3 and 9 or 8 and 7 or 0)
print(0 and False or False and 9 and 4>3)
print(True and False or 3>4 and not True)
成员运算(***)
in 在 not in 不在
s = 'alexTMDdsb'
print('TMD'not in s)
比较运算(**)
等于 ==
不等于 !=
大于 >
小于 <
大于等于 >=
小于等于 <=
身份运算
is 是
is not 不是
is 判断是不是同一个
== 判断是不是长得一样
编码
密码本 -- ascii 256 支持英文 ,不支持中文
今 天 晚 上 去 行 动
00000001 0000002 00000010 110111011110101 8 位一断句
gbk -- 国标
英文 1个字节
中文 2个字节
unicode -- ascii gbk shift-JIS 2个
英文2个字节,中文4个字节
utf- 8 # 最流行的就是utf-8
英文 1个字节 欧洲 2 字节 亚洲 3 字节 最少用1个字节
utf-16 最少用2个字节
单位转换
1字节 = 8位
1Byte = 8bit
1024KB = 1MB
1024MB = 1GB
1024GB = 1TB 常用的就是TB
1024TB = 1PB
1024PB = 1EB
2.while循环 编码的初识,逻辑运算符 格式化输出的更多相关文章
- python基础之 while 逻辑运算符 格式化输出等
1.while循环 while 条件: 循环体 while 条件: 循环体 else: 循环体 重点: 当条件为真的时候,就进入循环体,从上到下依次执行,执行完最后一条语句时,while并不是直接退出 ...
- while循环,break和continue,运算符,格式化输出
一丶while循环 while条件: 代码块(循环体) #数数 打印1-100 count = 1 while count <= 100: print(count) count += 1 执行顺 ...
- pycharm初识及格式化输出
#_*_coding:utf-8_*_#作者:王佃元#日期:2019/12/6 #格式化输出name = input("Name")age = input("Age&qu ...
- python 全栈开发,Day2(in,while else,格式化输出,逻辑运算符,int与bool转换,编码)
一.in的使用 in 操作符用于判断关键字是否存在于变量中 a = '男孩wusir' print('男孩' in a) 执行输出: True in是整体匹配,不会拆分匹配. a = '男孩wusir ...
- Python全栈开发,Day2(in,while else,格式化输出,逻辑运算符,int与bool转换,编码)
一.in的使用 in 操作符用于判断关键字是否存在于变量中 ? 1 2 a = '男孩wusir' print('男孩' in a) 执行输出: True in是整体匹配,不会拆分匹配. ? 1 2 ...
- while循环、格式化输出、运算符和编码初识
while循环 1. while循环的结构 while 条件: 执行语句1 执行语句2 i = 0 while i < 10: print(i) i += 1 运行结果 0 1 2 3 4 5 ...
- 记录我的 python 学习历程-Day02-while 循环/格式化输出/运算符/编码的初识
一.流程控制之--while 循环 循环就是重复做同一件事,它可以终止当前循环,也可以跳出这一次循环,继续下一次循环. 基本结构(基本循环) while 条件: 循环体 示例 # 这是一个模拟音乐循环 ...
- while循环,格式化输出,运算符及编码初识
一.while循环 1.基本循环(死循环) while 条件: 循环体 2.使用while计数 count = 0 # 数字里面非零的都为True while True: count = count ...
- day 02 while 循环 格式化输出 运算符 and or not - 编码的初识
while 循环 while 条件: 循环体 循环如何终止? 改变条件. flag = Truewhile flag: print('狼的诱惑') print('我们不一样') ...
随机推荐
- Android——坐标系及转化
一.坐标系 Android应用层坐标系原点在左上角,坐标范围(0,0)——(width,height). Android底层坐标系原点在屏幕中央,坐标范围(-1000,,1000)——(1000,10 ...
- async & await 的前世今生(Updated)----代码demo
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- requirejs中的define
关于requirejs中的define的原理理解 我们已经了解到模块模式是为单例创建私有变量和特权方法的.一个最基本的例子: var foo=(function(){ var something= ...
- 安装Sublime配合quick-cocos2d-x开发
下载地址 Sublime下载地址 安装 Package Control 在Sublime中,按Ctrl+~打开控制台,输入: Sublime Text2 import urllib2,os; pf=' ...
- openwrt: patch-dtb
dts的概念是linux kernel中的,跟openwrt的关系不大.只是恰好在学习openwrt的时候碰到了这个东西,所以记录在openwrt名下. patch-dtb openwrt对arch/ ...
- LeetCode(3)题解: Longest Palindromic Substring
https://leetcode.com/problems/longest-palindromic-substring/ 题目: Given a string S, find the longest ...
- 基于node+koa2+mongodb实现简单的导航管理系统
基于node+koa2+mongodb实现简单的导航管理系统 项目说明 本项目gitbub地址 https://github.com/xuess/nav-admin,喜欢请star 基于node 实现 ...
- MapReduce算法形式二:去重(shuffle)
案例二:去重(shuffle/HashSet等方法)shuffle主要针对的是key去重HashSet主要针对values去重
- redis的图形界面管理工具
大部分人都知道redis是一款用在缓存服务器上的软件,它与memcache类似,都可以存储海量的数据,用在大访问量的web网站.聊天记录存放等方面,但是又与memcache不同: 1.缓存数据可以持久 ...
- 数据库DCL、DDL、DML、DQL
SQL三部分:data manipulation language DCL: (控制)管理用户权限(GRANT.REVOKE),数据库整体配置 DDL: (定义)作用于数据库,表, ...