PythonStudy——数据类型转化 Data type conversion
类型转换
1.数字类型:int() | bool() | float()
2.str与int:int('10') | int('-10') | int('0') | float('-.5') | float('3.14') | str(数字)
3.重点 - str与list:
'abc' => ['a', 'b', 'c']: list('abc') | ''.join(['a', 'b', 'c'])
'abc|def|xyz' => ['abc', 'def', 'xyz']: s.split('|') | '|'.join(ls)
4.list、set、tuple:类型()
5.list与dict:
a=1&b=2&c=3 <=> [('a', 1), ('b', 2), ('c', 3)] <=> {'a': 1, 'b': 2, 'c': 3}
dic = {}
for k, v in [('a', 1), ('b', 2), ('c', 3)]:
dic[k] = v
ls = []
for k, v in {'a': 1, 'b': 2, 'c': 3}.items():
ls.appen((k, v))
6.可以通过字典构建任意数据的映射关系
type_map = {
1: '壹',
'壹': 1,
'owen':(1, 88888),
'add': add # add是功能(函数)
}
PythonStudy——数据类型转化 Data type conversion的更多相关文章
- PythonStudy——数据类型总结 Data type summary
按存储空间的占用分(从低到高) 数字 字符串 集合:无序,即无序存索引相关信息,可变.集合中的元素必须是可hash的,即不可变的数据类型. 元组:有序,需要存索引相关信息,不可变 列表:有序,需要存索 ...
- JAVA 1.2(原生数据类型 Primitive Data Type)
1. Java的数据类型分为2类 >> 原生数据类型(primitive data type) >> 引用数据类型(reference data type) 3. 常量和变量 ...
- java 反射 报错:Attempt to get java.lang.Integer field "..." with illegal data type conversion to int
类: Integer id; 反射时: Field f = User.class.getDeclaredField("id"); f.setAccessible(true); in ...
- C++数据类型(data type)介绍
在编写程序时,数据类型(data type)定义了使用存储空间的(内存)的方式. 程序员通过定义数据类型(data type),告诉特定存储空间这里要存储的数据类型是什么,以及你即将操作他的方式.(注 ...
- MySQL数据类型(DATA Type)与数据恢复与备份方法
一.数据类型(DATA Type)概述 MySQL支持多种类型的SQL数据类型:数字类型,日期和时间类型,字符串(字符和字节)类型以及空间类型 数据类型描述使用以下约定: M表示整数类型的最大显示宽度 ...
- 数据类型(data type)
基本数据类型(primitive data type):字符型(2个字节),布尔型(一位),byte(1个字节),short(两个字节),int(4个字节),long(8个字节),float(2个字节 ...
- JAVA 1.3 (原生数据类型 Primitive Data Type)续
1. 原生数据类型一共有4类8种 >> 整数类型 int表示一个int代表32位 2^32(-2147483648 - 2147483647) >> 字符类型 byte 表示一 ...
- Data type conversion in MongoDB
[问题] I have a collection called Document in MongoDB. Documents in this collection have a field calle ...
- 【你吐吧c#每日学习】11.10 C# Data Type conversion
implicit explicit float f=12123456.213F int a = Convert.ToInt32(f); //throw exception or int a = (in ...
随机推荐
- JS中for in 与 for of
// 数组var A=[4,6,74,67]; for in:拿到的是数组下标 for (let i in A){ console.log(i); } //0,1,2,3 for of:拿到的是数组元 ...
- SQL Server数据归档的解决方案
SQL Server数据归档的解决方案 最近新接到的一项工作是把SQL Server中保存了四五年的陈年数据(合同,付款,报销等等单据)进行归档,原因是每天的数据增量很大,而历史数据又不经常使用, ...
- guxh的python笔记三:装饰器
1,函数作用域 这种情况可以顺利执行: total = 0 def run(): print(total) 这种情况会报错: total = 0 def run(): print(total) tot ...
- 超轻量级Json框架SmartObject
最近我在codeplex上发了一个项目SmartObject(基于framework4.5,目前是1.0版本).用法如下: // HowToUse using Spider.Data; //json ...
- 安卓MVP框架
一.理解MVP 原文地址 我的Demo 效果图: 项目结构: 实现 一.Model层 首先定义一个实体类User package app.qcu.pmit.cn.mvpdemo.model; /** ...
- sevrlet进行用户名密码校验
在eclipse中建立了web项目,实现注册和登录还有在个人中心显示用户名密码 注册功能 源码如下 package com.sevlet.demo; import java.io.IOExceptio ...
- vscode sass live compiler
{ "liveSassCompile.settings.formats": [{ "format": "expanded", "e ...
- easyui datebox时间控件如何只显示年月
easyui datebox控件,只显示年月,不显示年月日 需要的效果图如下: 具体的js代码: <script> $(function(){ intiMonthBox('costTime ...
- 微服务-封装-docker by daysn大雄
目录 序言一.什么是容器二.docker入门 2.1安装启动2.2docker使用 2.2.1 helloworld 2.2.2 容器 2.2.3 镜像 2.2.4 容器的连接 序言 虚拟化一 ...
- python全栈开发笔记---------数据类型****整理****
一.数字 int(..) 二.字符串 replace/find/join/strip/startswith/split/upper/lower/format tempalet ='i am {name ...