python 对象
来源:互联网 发布:前端连接数据库 编辑:程序博客网 时间:2024/06/06 10:51
目标,能够查看python对象属性和文档
python自带的对象很多
>>> int#整数<class 'int'>>>> str#字符串<class 'str'>>>> float#浮点数<class 'float'>>>>
字符串的赋值
>>> c = "hello">>> b = 'hello'>>> d = """hello""">>> e = '''hello'''>>> c==bTrue>>> b==dTrue>>> e==cTrue>>> type(c)<class 'str'>>>>
type
可以查看对象类型.
上述赋值方法都可以用于字符串赋值,按照python
简洁的风格,建议使用b='hello'
的形式.
字符串的属性
>>> dir(c)['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']>>>
dir
可以查看拥有什么属性
则这属性的描述可以这样查看
>>> c.split.__doc__'S.split(sep=None, maxsplit=-1) -> list of strings\n\nReturn a list of the words in S, using sep as the\ndelimiter string. If maxsplit is given, at most maxsplit\nsplits are done. If sep is not specified or is None, any\nwhitespace string is a separator and empty strings are\nremoved from the result.'
__doc__
这个一般的对象都拥有的,也就是帮助文档,建议以后写函数的时候尽量写该属性.
python
还有其他自带的很多属性和方法,可以按照以上的方法学习和使用.
阅读全文
0 0
- Python对象
- python对象
- Python对象
- python 对象
- Python对象
- Python对象
- Python对象
- Python---对象
- Python 对象
- Python 对象
- python 对象
- python 对象
- Python -- 对象和面向对象
- Python对象之基础对象
- python中的对象 一级对象?
- Python学习笔记-Python对象
- Python核心编程----Python对象
- Python基础语法-Python对象
- C# 结合html5 批量上传文件和图片预览
- java 不同的package下同类明的冲突以及解决办法
- thinkphp alias ,field的连贯操作,查询一次数据库,计算两个值
- svn乱码
- 弱鸡3,C# 一个Timer在等待过程中,interval被改变,时间如何处理,
- python 对象
- vue---watch用法
- Web在jsp页面中生成柱状图,折线图,饼状图
- Kotlin Android 环境搭建
- java.lang.VerifyError: Verifier rejected class bad method
- 5、Spring技术栈-客户端、服务端数据验证
- LeetCode 617. Merge Two Binary Trees
- Hadoop关键技术理解
- HTTP状态码