Lesson02_python3之 基础数据类型

来源:互联网 发布:淘宝上有正规药店吗 编辑:程序博客网 时间:2024/06/05 18:54

基础数据类型:

整数型:

python中,任何不带小数点的数字都是整数 二进制:逢二进一 十进制:逢十进一 十六进制:逢十六进一,数据以 ox开头 数据精确。

浮点数:

不带小数点都是浮点数 数据并非精确,小数点后保留16位,16位后的舍弃 python中的浮点数,小数点后有16位,15位有效

字符串:

有三种表示方式: '字符串' "字符串" '''字符串''' #比较受推荐的方式,会保留''' '''内的原有格式 字符串前加r,表示字符串内容不进行转义

   bool型:

      True 真      False 假

标识符约定:

不要用python预定义的标识符命名 不要用python内置函数名或内置数据类型或异常名做标识符 避免标识符名开头 或 结尾使用下划线(python 用这种方法大量定义了特殊方法和变量)

逻辑运算:

and:  全True才True or: 一True即True not: 非,取反

转义字符(\):

转义字符描述\(行尾)续行符\\\\'单引号\"双引号\a响铃\b退格\e转义\000\n换行\v纵向制表符\t横向制表符\r回车\f换页\oyy八进制数yy代表的字符,例如:\o12,代表换行\xyy十进制数yy代表的字符,例如:\x0a,代表换行\other其他的字符以普通格式输出

代码:

#!/usr/bin/env python# -*- coding: utf-8 -*-#python3 代码,wing ware 5 编辑intnum = 1print(type(intnum))floatnum = 1.2print(type(floatnum))print("")str1 = 'hello python'str2 = "hello python"str3 = '''hellopython'''#str格式化的三种方式:print("str1:{_str1},str2:{_str2},str3:{_str3}".format(_str1=str1,_str2=str2,_str3=str3))print("str1:{0},str2:{1},str3:{2}".format(str1,str2,str3))print("str1:%s,str2:%s,str3:%s" %(str1,str2,str3))if len(str1)>0 and len(str2):    print("str1 和 str2 的长度都大于0")    if len(str1)>0 or len(str2):    print("str1 和 str2 中,至少有一个值的长度大于0")    if not len(str1)<0:    print("str1 的长度大于0")

运行结果:

<class 'int'><class 'float'>str1:hello python,str2:hello python,str3:hellopythonstr1:hello python,str2:hello python,str3:hellopythonstr1:hello python,str2:hello python,str3:hellopythonstr1 和 str2 的长度都大于0str1 和 str2 中,至少有一个值的长度大于0str1 的长度大于0