#!/usr/bin/python3
#python的基本语法和数据类型
#python3中 一行有多个语句,用分号分割(;)
print("aaa") ;print("bbb") #基本数据类型,移除long类型
print(type(1))
print(type(1.0))
print(type("str")) #允许多个变量连续赋值
a=b=c=1
print(a,b,c) a,b,c=1,2,"bb"
print(a,b,c) #标准数据类型6种
#Number(数字)
#String(字符串)
#List(列表)
#Tuple(元组)
#Sets(集合)
#Dict(字典) #Number(数字)
#支持 int float bool complex(复数)
#数值计算
print("5+3=",5+3)
print("5-3=",5-3)
print("5*3=",5*3)
print("除法得到浮点数 2/4=",2/4)
print("除法得到整数 2//4=",2//4)
print("取余 10%3=",10%3)
print("乘方 4**2=",4**2)
print("开方 4**0.5=",4**0.5) #String(字符串)
#元素是不可变的
string="abcdefg"
print(string)
print(string[0])
print(string[0:-1])#从头到尾
print(string[2:])#从下标2开始到尾
print(string[2:4])#从下标2到n-1 [m,n)
print(string*2)#输出2次 #list(列表)
#元素可变的
listDemo=["aa",1,"bb",2]
print(listDemo)
print(listDemo[0])#输出下标0
print(listDemo[2:])#从下标2开始到尾
print(listDemo[1:3])#从下标2到n-1 [m,n)
print(listDemo*2)#输出2次
listDemo[0]="替换的"
print(listDemo)#修改后的 #tuple(元组)
#元素不可变的
tupleDemo=("aa",1,"bb",2)
print(tupleDemo)
print(tupleDemo[0])#输出下标0
print(tupleDemo[2:])#从下标2开始到尾
print(tupleDemo[1:3])#从下标2到n-1 [m,n)
print(tupleDemo*2)#输出2次 tupleDemo=()#空元组
tupleDemo=(a,)#一个元素
print(tupleDemo) #Set(集合)
#一个无序不可重复的序列
setDemo={"a","b","c"}
print("集合A ",setDemo)
#集合可以做 交集并集差集
setDemo2={"a","b"}
print("集合B ",setDemo2)
print("AB的差集 ",setDemo-setDemo2)
print("AB的并集 ",setDemo|setDemo2)
print("AB的交集 ",setDemo&setDemo2)
print("AB的不同时存在的 ",setDemo^setDemo2) #字典
dictDemo={"tom":"","jerry":""}
print(dictDemo)
print(dictDemo["tom"])
print("keys:",dictDemo.keys())
print("values",dictDemo.values())
#移除 key 返回value
print("移除tom ",dictDemo.pop("tom"))
print(dictDemo) #python常用数据转换
'''
int(x)
str(x)
tuple(s) 将序列转换成元组
list(s) 将序列转换成列表
''' #python的注释
print("单行注释 #")
print("多行注释 单引号(3个')")
print("多行注释 双引号(3个双引号)")

Python:标准数据类型6种的更多相关文章

  1. Python 标准数据类型

    标准数据类型: Number(数字)----int float bool complex(复数) String(字符串) List(列表) Tuple(元组) Dictionary(字典) Set(集 ...

  2. Python标准数据类型的二次加工

    基于类继承的原理实现: class Li(list): #继承标准数据类型 list def app(self,p_object): #派生出新的 append功能 if not isinstance ...

  3. python标准数据类型

    Python3 中有六个标准的数据类型: Number(数字) String(字符串) List(列表) Tuple(元组) Sets(集合) Dictionary(字典) Python 中的变量不需 ...

  4. python标准数据类型 Bytes

    预备知识: bin(): """ Return the binary representation of an integer. >>> bin(279 ...

  5. Python:6种标准数据类型

    原文地址https://www.cnblogs.com/qin1991/p/5910145.html #!/usr/bin/python3 #python的基本语法和数据类型 #python3中 一行 ...

  6. python基础之五大标准数据类型

    学习一门语言,往往都是从Hello World开始. 但是笔者认为,在一个黑框框中输出一个"你好,世界"并没有什么了不起,要看透事物的本质,熟悉一门语言,就要了解其底层,就是我们常 ...

  7. Python3基础教程2——Python的标准数据类型

    2018年3月12日 这次介绍一些python里面的标准数据类型 当然还是推荐一个比较系统的教程 http://www.runoob.com/python3/python3-tutorial.html ...

  8. python认知及六大标准数据类型

    --- typora-root-url: assets --- ### -python的认知 ``` 89年开发的语言,创始人范罗苏姆(Guido van Rossum),别称:龟叔(Guido). ...

  9. 140种Python标准库、第三方库和外部工具

    导读:Python数据工具箱涵盖从数据源到数据可视化的完整流程中涉及到的常用库.函数和外部工具.其中既有Python内置函数和标准库,又有第三方库和工具. 这些库可用于文件读写.网络抓取和解析.数据连 ...

随机推荐

  1. 【POJ】2117 Electricity

    无向图求割点和连通块. /* POJ2117 */ #include <iostream> #include <vector> #include <algorithm&g ...

  2. 【HDOJ】2782 The Worm Turns

    DFS. /* 2782 */ #include <iostream> #include <queue> #include <cstdio> #include &l ...

  3. wcf资料

    WCF服务安全控制之netTcpBinding的用户名密码验证http://www.cnblogs.com/wengyuli/archive/2011/05/14/wcf-nettcpbinding- ...

  4. Hash(4) hashtable,hashmap

    首先,我们要知道set是利使用map是实现的,因为只要利用map中的key唯一性就行了. 1.hashmap 和hashtable的区别是什么? 我们可以背出:  hashtable线程安全.hash ...

  5. Eclipse的下载和安装

    下载 Android开发首选Eclipse for Android Developers版本,里面集成了ADT(Android Development Tools). 下载页面:http://www. ...

  6. Conversion between json and object using SBJson lib

    Define two methods in an object class as follows: @interface MyObject : NSObject @property (nonatomi ...

  7. 从m个数中取top n

    将题目具体一点,例如,从100个数中取出从大到小排前10的数 方法1:使用快速排序 因为快速排序一趟下来,小于K的数都在K的前面,大于K的数都在K的后面 如果,小于K的数有35个,大于K的数有64个 ...

  8. linux —— shell 编程(编程语法)

    导读 本文为博文linux —— shell 编程(整体框架与基础笔记)的第4小点的拓展.(本文所有语句的测试均在 Ubuntu 16.04 LTS 上进行) 目录 再识变量 函数 条件语句 循环语句 ...

  9. AFNetworking2.0 NSHipster翻译

    AFNetworking 是当前 iOS 和 Mac OS X 开发中最广泛使用的开源项目之一.它帮助了成千上万叫好又叫座的应用,也为其它出色的开源库提供了基础.这个项目是社区里最活跃.最有影响力的项 ...

  10. 「S-A-L-T-A」项目失败总结!

    前言: 从2013年8月20日进入这个项目开始,到现在12月12日. 从项目详细设计开始,到现在连SI2阶段的疏通测试都没有完成! (现在,这个项目好像已经不需要我们再做下去了...) 项目失败原因总 ...