标签:pyc one pytho 数据类型 字符 user usr print 整数
查看数据类型:type()
类型转换:int(),float(),char(),ord(),str(),bool()
#coding:utf-8 #/usr/bin/python """ 2018-11-03 dinghanhua 查看数据类型,类型转换 """ """查看数据类型type()""" print(type(1),type(3.14), type(‘a‘),type(‘abd‘), type((1,2,3)),type(True),type(None), type([]),type({1,2}),type({1:‘monday‘,2:‘tuesday‘})) """强制类型转换""" """整数,浮点数,ascii码转换:int(),float(),chr(),ord()""" f = 3.14 print(‘f=%f,int(f)=%d ‘%(f,int(f))) print(float(int(f))) print(chr(65)) #整数转化为ascii码字符 print(ord(‘a‘)) #ascii字符转化为整数 ‘‘‘转成布尔类型 bool()‘‘‘ print(bool(‘1‘),bool(‘0‘),bool([0])) #True print(bool(‘‘),bool(0),bool([]),bool(()),bool({})) #False ‘‘‘字符串 str()‘‘‘ print(type(str(f))) ‘‘‘特殊字符-转义字符 r忽略转义字符‘‘‘ print(‘abc\nghigk\tjfwejf\\fjewfjoewjfjfwejgwe\‘jfwifoe?‘) print(r‘abc\nghigk\tjfwejf\\fjewfjoewjfjfwejgwe\‘jfwifoe?‘) print(‘c:\\user\\pycharm‘) #\\转义\ print(r‘c:\user\pycharm‘) #用r无需加转义 print("i‘m busy") #里面带‘的用" print(‘he said:"ok"‘) #里面带"用‘
the end!
标签:pyc one pytho 数据类型 字符 user usr print 整数
原文地址:https://www.cnblogs.com/dinghanhua/p/9901600.html