python编码问题和逻辑运算
1,回顾昨天课程及作业
#1、使用while循环输入 1 2 3 4 5 6 8 9 10
'''
count = 0
while count < 10:
count += 1 # count = count + 1
if count == 7:
print(' ')
else:
print(count) count = 0
while count < 10:
count += 1 # count = count + 1
if count == 7:
continue
print(count)
'''
#3、输出 1-100 内的所有奇数
#方法一:
# count = 1
# while count < 101:
# print(count)
# count += 2
#方法二:
# count = 1
# while count < 101:
# if count % 2 == 1:
# print(count)
# count += 1 #5、求1-2+3-4+5 ... 99的所有数的和
# sum = 0
# count = 1
# while count < 100:
# if count % 2 == 0:
# sum = sum - count
# else:
# sum = sum + count
# count += 1
# print(sum) #6、用户登陆(三次机会重试)
#input 心中有账号,密码 while i = 0
while i < 3:
username = input('请输入账号:')
password = int(input('请输入密码:'))
if username == '咸鱼哥' and password == 123:
print('登录成功')
else:
print('登录失败请重新登录')
i += 1
2,格式化输出
#格式化输出
# % s d
# name = input('请输入姓名')
# age = input('请输入年龄')
# height = input('请输入身高')
# msg = "我叫%s,今年%s 身高 %s" %(name,age,height)
# print(msg)
"""
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)
"""
name = input('请输入姓名')
age = input('请输入年龄')
height = input('请输入身高')
msg = "我叫%s,今年%s 身高 %s 学习进度为3%%s" %(name,age,height)
print(msg)
3,while else循环语句
count = 0
while count <= 5 :
count += 1
if count == 3:break
print("Loop",count) else:
print("循环正常执行完啦")
print("-----out of while loop ------")
4,初始编码
01010100 新
11010000 开
11010100 一
01100000 家
11000000 看
11000000 看 01010100011101110101011110110
A B C
01000001 01000010 01000011
电报,电脑的传输,存储都是01010101 最早的'密码本' ascii 涵盖了英文字母大小写,特殊字符,数字。
01010101
ascii 只能表示256种可能,太少,
创办了万国码 unicode
16表示一个字符不行,32位表示一个字符。
A 01000001010000010100000101000001
B 01000010010000100100001001000010
我 01000010010000100100001001000010
Unicode 升级 utf-8 utf-16 utf-32
8位 = 1字节bytes
utf-8 一个字符最少用8位去表示,英文用8位 一个字节
欧洲文字用16位去表示 两个字节
中文用24 位去表示 三个字节
utf-16 一个字符最少用16位去表示 gbk 中国人自己发明的,一个中文用两个字节 16位去表示。 11000000 1bit 8bit = 1bytes
1byte 1024byte = 1KB
1KB 1024kb = 1MB
1MB 1024MB = 1GB
1GB 1024GB = 1TB
5,逻辑运算
#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)) # 1
# print(int(False)) # 0 '''x or y x True,则返回x'''
# print(1 or 2) # 1
# print(3 or 2) # 3
# print(0 or 2) # 2
# print(0 or 100) # 100 # print(2 or 100 or 3 or 4) # 2 # print(0 or 4 and 3 or 2)
'''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)
python编码问题和逻辑运算的更多相关文章
- (转载) 浅谈python编码处理
最近业务中需要用 Python 写一些脚本.尽管脚本的交互只是命令行 + 日志输出,但是为了让界面友好些,我还是决定用中文输出日志信息. 很快,我就遇到了异常: UnicodeEncodeError: ...
- Python 编码简单说
先说说什么是编码. 编码(encoding)就是把一个字符映射到计算机底层使用的二进制码.编码方案(encoding scheme)规定了字符串是如何编码的. python编码,其实就是对python ...
- Python之路3【知识点】白话Python编码和文件操作
Python文件头部模板 先说个小知识点:如何在创建文件的时候自动添加文件的头部信息! 通过:file--settings 每次都通过file--setings打开设置页面太麻烦了!可以通过:View ...
- python编码规范
python编码规范 文件及目录规范 文件保存为 utf-8 格式. 程序首行必须为编码声明:# -*- coding:utf-8 -*- 文件名全部小写. 代码风格 空格 设置用空格符替换TAB符. ...
- 【转】python编码的问题
摘要: 为了在源代码中支持非ASCII字符,必须在源文件的第一行或者第二行显示地指定编码格式: # coding=utf-8 或者是: #!/usr/bin/python # -*- coding: ...
- 【转】python编码规范
http://blog.csdn.net/willhuo/article/details/49300441 决定开始Python之路了,利用业余时间,争取更深入学习Python.编程语言不是艺术,而是 ...
- python 编码 UnicodeDecodeError
将一个py脚本从Centos转到win运行,出错如下: UnicodeDecodeError: 'gbk' codec can't decode byte 0xff in position 0: il ...
- Python编码/文件读取/多线程
Python编码/文件读取/多线程 个人笔记~~记录才有成长 编码/文件读取/多线程 编码 常用的一般是gbk.utf-8,而在python中字符串一般是用Unicode来操作,这样才能按照单个字 ...
- 关于Python编码,超诡异的,我也是醉了
Python的编码问题,真是让人醉了.最近碰到的问题还真不少.比如中文文件名.csv .python对外呈现不一致啊,感觉好不公平. 没图说个JB,下面立马上图. 我早些时候的其他脚本,csv都是 ...
随机推荐
- 【JMeter】选项-函数助手对话框应用举例
String date="${__javaScript((new Date()).getFullYear()+'-'+((new Date()).getMonth()+1)+'-'+(new ...
- iOS voip电话和sip软电话 --网络电话
一|介绍1.两者区别: SIP软电话与IP电话在技术上属于同一类型,只是SIP软电话是使用电脑软件实现的,而IP电话有一部分是在话机中直接写入了程序,可以通过硬件直接使用.IP(简称VoIP,源自英语 ...
- Swift 开源项目练习应用
小的View.动画实现练习 拥有着苹果先天生态优势的Swift自发布以来,各种优秀的开源项目便层出不穷.本文作者站在个人的角度,将2014年Swift开源项目做了一个甄别.筛选,从工具.存储.网络.界 ...
- 关于《ASP.NET MVC企业级实战》
大家好,我的书<ASP.NET MVC企业级实战>已经出版啦,感谢大家过去的关注与支持!前言部分,出版的时候漏了部分内容,我这里将其贴出来. 本书提供源码和教学PPT课件!(源码在书中第3 ...
- 英雄联盟LOL用什么语言写的?
是用openGL开发的 开发语言是c/c++ 客户端是一个.net的web界面
- The Hungarian Abhorrence Principle
原文:http://www.butunclebob.com/ArticleS.UncleBob.TheHungarianAbhorrencePrinciple The Hungarian Abh ...
- js随机数生成,生成m-n的随机数
使用js生成n到m间的随机数字,主要目的是为后期的js生成验证码做准备,Math.random()函数返回0和1之间的伪随机数 var random = Math.random(); console. ...
- 三十天学不会TCP,UDP/IP网络编程-TraceRoute的哲学
新年快乐,继续来部分粘贴复制我的这一系列文章啦,如果对和程序员有关的计算机网络知识,和对计算机网络方面的编程有兴趣,欢迎去gitbook(https://www.gitbook.com/@rogerz ...
- Webpack 2 视频教程 011 - Webpack2 中加载 CSS 的相关配置与实战
原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」. Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本讲 ...
- 源码中的哲学——通过构建者模式创建SparkSession
spark2.2在使用的时候使用的是SparkSession,这个SparkSession创建的时候很明显的使用了创建者模式.通过观察源代码,简单的模拟了下,可以当作以后编码风格的参考: 官方使用 i ...