#!/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. 如何启用Service,如何停用Service

    一.步骤 第一步:继承Service类 public class SMSService extends Service { } 第二步:在AndroidManifest.xml文件中的<appl ...

  2. 【转】Linux命令之查看文件占用空间大小-du,df

    原文网址:http://blog.csdn.net/wangjunjun2008/article/details/19840671 du(disk usage),顾名思义,查看目录/文件占用空间大小 ...

  3. 动态规划(树形DP):HDU 5886 Tower Defence

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA2MAAAERCAIAAAB5Jui9AAAgAElEQVR4nOy9a6wsS3YmFL/cEkh4LP

  4. JavaScript 模块化加载

    存在AMD(Asynchronous Module Definition异步模块定义)规范和CMD(Common Module Definition通用模块定义)规范.对于依赖的模块,AMD是提前执行 ...

  5. 计算1到n整数中,字符ch出现的次数

    个位ch个数 + 十位ch个数 * 10 + 百位ch个数 * 100:同时如果某一位刚好等于ch,还需要减去多算的一部分值. #include <stdio.h> //整数1到n,字符c ...

  6. 银联手机支付(.Net Csharp),3DES加密解密,RSA加密解密,RSA私钥加密公钥解密,.Net RSA 3DES C#

    前段时间做的银联支付,折腾了好久,拼凑的一些代码,有需要的朋友可以参考,本人.Net新手,不保证准确性! 这个银联手机支付没有SDK提供,技术支持也没有.Net的,真心不好搞! RSA加解密,这里有个 ...

  7. C#中HashTable的用法示例2

    命名空间 System.Collections 名称 哈希表(Hashtable) 描述 用于处理和表现类似keyvalue的键值对,其中key通常可用来快速查找,同时key是区分大小写:value用 ...

  8. TPL中的task并不是thread

    Tasks are not Threads - The Brain Dump用了一个非常简单直观的例子说明了task和thread并不是一回事(尽管你调用Task.Run一般会在线程池上启一个线程帮你 ...

  9. 分享一个很好看的WPF界面

    今天在http://www.iopenworks.com/Products/ProductDetails/Introduction?proID=386 上面看到的,先mark下来...... 地址:h ...

  10. android:ImageView 和ImageButton的区别

    1.继承不同: java.lang.Object ↳ android.view.View ↳android.widget.ImageView ↳ android.widget.ImageButton ...