python note 02 格式化与判断、字符串转换
1、格式化输出%
%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)
ps:输入的内容要与格式化输出的数量的相匹配
2、格式化输出如果有%,就用%%转义
name = input('请输入姓名')
age = input('请输入年龄')
height = input('请输入身高')
msg = "我叫%s,今年%s 身高 %s 学习进度为3%%s" %(name,age,height)
print(msg)
3、当while else 语句被break打断了,将不会执行else语句,将break改为pass,程序将继续执行else语句
count = 0
while count <= 5 :
count += 1
if count == 3:break
print("Loop",count) else:
print("循环正常执行完啦")
print("-----out of while loop ------")
4、
最早的'密码本' 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位去表示。
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) # T
print(2 > 1 and 1 < 4 or 2 < 3 and 9 > 6 or 2 < 4 and 3 < 2) # T
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 #也可以从前往后看
True and ==> 继续看后面
True or ==> True
False and ==> False
False or ==> 继续看后面
ps:int ----> bool 非零转换成bool True,0 转换成bool 是False
print(bool(2)) # T
print(bool(-2)) # T
print(bool(0)) # F
# #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) #
'''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) # T
#(以数字为例)从前往后看,如果遇到and,两边都为True的话输出后面的数字,如果一边为False则输出0.
6、字符串转换
#将字符串转化为数字
a = ""
print(type(a),a)
#输出<class 'str'> 123
b = int(a)
print(type(b),b)
#输出<class 'int'> 123
#将八进制转化为十进制
num = ""
v = int(num, base= 8)
print(v)
#输出64
#将十六进制转化为十进制
num = ""
v = int(num, base= 16)
print(v)
#输出256
python note 02 格式化与判断、字符串转换的更多相关文章
- python note 03 切片及对字符串操作
1.计算 1 - 2 + 3 ... + 99 中除了88以外的数之和 i = 1 sum = 0 while i < 100 : if i == 88 : i = i + 1 continue ...
- python学习笔记(datetime、字符串转换)
datetime对象与字符串可以互相转化 代码如下: from datetime import datetime def datetime_string(time): return time.strf ...
- python基础入门 整型 bool 字符串
整型,bool值,字符串 一.整型 整型十进制和二进制 整型:整型在Python中的关键字用int来表示; 整型在计算机中是用于计算和比较的 可进行+ - * / % //(整除) **(幂运算) 十 ...
- Delphi判断字符串中是否包含汉字,并返回汉字位置
//1,函数代码{判断字符串是否包含汉字// judgeStr:要判断的字符串//posInt:第一个汉字位置}function TForm2.IsHaveChinese(judgeStr: stri ...
- Python判断字符串编码以及编码的转换
转自:http://www.cnblogs.com/zhanhg/p/4392089.html Python判断字符串编码以及编码的转换 判断字符串编码: 使用 chardet 可以很方便的实现字符串 ...
- Python系列之模块、和字符串格式化
Python 模块 模块让你能够有逻辑地组织你的Python代码段. 把相关的代码分配到一个 模块里能让你的代码更好用,更易懂. 模块也是Python对象,具有随机的名字属性用来绑定或引用. 模块分为 ...
- Python数据类型-02.字符串
本文主要记录字符串的相关知识,包括字符串的定义特点,常用方法和 请知悉: 计算机中,一切皆为对象世界万物,皆为对象,一切对象皆可分类 1.什么是字符串? 类似"hello world&quo ...
- Python语法速查: 3. 字符串格式化
返回目录 (1)简易字符串格式化 字符串属于不可变序列,只能生成新的,不能改变旧的.“字符串格式化”有点像以前C语言的sprintf,可以将若干变量代入格式化的字符串,生成一个符合要求的新字符串. 转 ...
- 14.python类型总结,集合,字符串格式化
借鉴:https://www.cnblogs.com/linhaifeng/articles/5935801.html https://www.cnblogs.com/wupeiqi/article ...
随机推荐
- 重建二叉树(JAVA)
重建二叉树 题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字. 例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历 ...
- Spring Boot - 配置介绍
Spring Boot 针对常用的开发场景提供了一系列自动化配置来减少原本复杂而又几乎很少改动的模板配置内容,但是,我们还是需要了解如何在Spring Boot中修改这些自动化的配置,以应对一些特殊场 ...
- Intellij中部署Tomcat(详细版本-介绍了部署完之后的详细路径)
https://blog.csdn.net/HughGilbert/article/details/56424137 要点如下: 1. CATALINA_HOME即Tomcat的安装目录 2. CAT ...
- JavaBean是什么,POJO是什么
参考:https://stackoverflow.com/questions/3295496/what-is-a-javabean-exactly https://stackoverflow.com/ ...
- 学习vue容易忽视的细节
1.对于自定义标签名(组件名称),Vue.js 不强制要求遵循 W3C 规则 (小写,并且包含一个短杠),尽管遵循这个规则比较好.HTML 特性是不区分大小写的.所以,当使用的不是字符串模板,came ...
- IIS6.0+win2003部署MVC网站的一些问题
安装iis,framework环境不谈.MVC网站部署 步骤: 1.为程序新建一个应用程序池(将default的那个程序池作为模板就可以了) 2.web服务扩展一些启用一些必要的服务 3.新建网站 描 ...
- aspose.cells 插入图片
,,"d:\\1.jpg"); Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[iIndex]; pic.Placeme ...
- Using a ScrollView - RN4
使用滚动条. 1. import import {ScrollView} from "react-native"; 2. Using <ScrollView> ... ...
- Vue 路由及路由默认跳转
路由就是让根组件动态得去挂载其他组件: 步骤: //路由配置: //.安装 npm install vue-router --save / cnpm install vue-router --save ...
- 用python探索和分析网络数据
Edited by Markdown Refered from: John Ladd, Jessica Otis, Christopher N. Warren, and Scott Weingart, ...