{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "skip" }, "toc": "true" }, "source": [ "# Table of Contents\n", "
" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Python 数据类型" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## 进制\n", "\n", "- 二进制,01\n", "- 八进制,01234567\n", "- 十进制,0123456789\n", "- 十六进制,012345678910ABCDEF" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" }, "solution2": "hidden", "solution2_first": true }, "source": [ "## 整数\n", "如:18,37,84\n", "\n", "每一个整数都具备如下功能:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "solution2": "hidden" }, "outputs": [], "source": [ "class int(object):\n", " \"\"\"\n", " int(x=0) -> int or long\n", " int(x, base=10) -> int or long\n", " \n", " Convert a number or string to an integer, or return 0 if no arguments\n", " are given. If x is floating point, the conversion truncates towards zero.\n", " If x is outside the integer range, the function returns a long instead.\n", " \n", " If x is not a number or if base is given, then x must be a string or\n", " Unicode object representing an integer literal in the given base. The\n", " literal can be preceded by '+' or '-' and be surrounded by whitespace.\n", " The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to\n", " interpret the base from the string as an integer literal.\n", " >>> int('0b100', base=0)\n", " \"\"\"\n", " def bit_length(self): \n", " \"\"\" 返回表示该数字的时占用的最少位数 \"\"\"\n", " \"\"\"\n", " int.bit_length() -> int\n", " \n", " Number of bits necessary to represent self in binary.\n", " >>> bin(37)\n", " '0b100101'\n", " >>> (37).bit_length()\n", " \"\"\"\n", " return 0\n", "\n", " def conjugate(self, *args, **kwargs): # real signature unknown\n", " \"\"\" 返回该复数的共轭复数 \"\"\"\n", " \"\"\" Returns self, the complex conjugate of any int. \"\"\"\n", " pass\n", "\n", " def __abs__(self):\n", " \"\"\" 返回绝对值 \"\"\"\n", " \"\"\" x.__abs__() <==> abs(x) \"\"\"\n", " pass\n", "\n", " def __add__(self, y):\n", " \"\"\" x.__add__(y) <==> x+y \"\"\"\n", " pass\n", "\n", " def __and__(self, y):\n", " \"\"\" x.__and__(y) <==> x&y \"\"\"\n", " pass\n", "\n", " def __cmp__(self, y): \n", " \"\"\" 比较两个数大小 \"\"\"\n", " \"\"\" x.__cmp__(y) <==> cmp(x,y) \"\"\"\n", " pass\n", "\n", " def __coerce__(self, y):\n", " \"\"\" 强制生成一个元组 \"\"\" \n", " \"\"\" x.__coerce__(y) <==> coerce(x, y) \"\"\"\n", " pass\n", "\n", " def __divmod__(self, y): \n", " \"\"\" 相除,得到商和余数组成的元组 \"\"\" \n", " \"\"\" x.__divmod__(y) <==> divmod(x, y) \"\"\"\n", " pass\n", "\n", " def __div__(self, y): \n", " \"\"\" x.__div__(y) <==> x/y \"\"\"\n", " pass\n", "\n", " def __float__(self): \n", " \"\"\" 转换为浮点类型 \"\"\" \n", " \"\"\" x.__float__() <==> float(x) \"\"\"\n", " pass\n", "\n", " def __floordiv__(self, y): \n", " \"\"\" x.__floordiv__(y) <==> x//y \"\"\"\n", " pass\n", "\n", " def __format__(self, *args, **kwargs): # real signature unknown\n", " pass\n", "\n", " def __getattribute__(self, name): \n", " \"\"\" x.__getattribute__('name') <==> x.name \"\"\"\n", " pass\n", "\n", " def __getnewargs__(self, *args, **kwargs): # real signature unknown\n", " \"\"\" 内部调用 __new__方法或创建对象时传入参数使用 \"\"\" \n", " pass\n", "\n", " def __hash__(self): \n", " \"\"\"如果对象object为哈希表类型,返回对象object的哈希值。哈希值为整数。在字典查找中,哈希值用于快速比较字典的键。两个数值如果相等,则哈希值也相等。\"\"\"\n", " \"\"\" x.__hash__() <==> hash(x) \"\"\"\n", " pass\n", "\n", " def __hex__(self): \n", " \"\"\" 返回当前数的 十六进制 表示 \"\"\" \n", " \"\"\" x.__hex__() <==> hex(x) \"\"\"\n", " pass\n", "\n", " def __index__(self): \n", " \"\"\" 用于切片,数字无意义 \"\"\"\n", " \"\"\" x[y:z] <==> x[y.__index__():z.__index__()] \"\"\"\n", " pass\n", "\n", " def __init__(self, x, base=10): # known special case of int.__init__\n", " \"\"\" 构造方法,执行 x = 123 或 x = int(10) 时,自动调用,暂时忽略 \"\"\" \n", " \"\"\"\n", " int(x=0) -> int or long\n", " int(x, base=10) -> int or long\n", " \n", " Convert a number or string to an integer, or return 0 if no arguments\n", " are given. If x is floating point, the conversion truncates towards zero.\n", " If x is outside the integer range, the function returns a long instead.\n", " \n", " If x is not a number or if base is given, then x must be a string or\n", " Unicode object representing an integer literal in the given base. The\n", " literal can be preceded by '+' or '-' and be surrounded by whitespace.\n", " The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to\n", " interpret the base from the string as an integer literal.\n", " >>> int('0b100', base=0)\n", " # (copied from class doc)\n", " \"\"\"\n", " pass\n", "\n", " def __int__(self): \n", " \"\"\" 转换为整数 \"\"\" \n", " \"\"\" x.__int__() <==> int(x) \"\"\"\n", " pass\n", "\n", " def __invert__(self): \n", " \"\"\" x.__invert__() <==> ~x \"\"\"\n", " pass\n", "\n", " def __long__(self): \n", " \"\"\" 转换为长整数 \"\"\" \n", " \"\"\" x.__long__() <==> long(x) \"\"\"\n", " pass\n", "\n", " def __lshift__(self, y): \n", " \"\"\" x.__lshift__(y) <==> x<