本篇对于数字有关的内置函数进行总结。

  数字包括 int() , long() , float() , complex() ,这些函数都能够用来进行数值类型的转换。同时这些函数也接受字符串参数,返回字符串所表示的数值。另外int()和long()在转换字符串的时候,还能接受一个进制参数,但如果是数字之间的类型转换,该参数不可用。

  后来python又引入了新的函数 bool() ,用来将整数值1和0转换成标准布尔值 True 和 False。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALcAAAEFCAIAAAAueeECAAAIh0lEQVR4nO3dbbLbNgyFYe2628g6ukn2hzuOTIIAJQqwQb7PdDy6inTjUmeoDwPxUQDL8e03MOU4tPev/ynG/R3Hf6QxHV/Z+nP8+XP8uf3O3r+h90vaEIyswQ0fg+gRlHtva+SXVAk4joOUOKkH8dmg+KVEPPzjK3HJVCbMoLxPGdWRHl9ZSMkPkEfwqaCcD/B7eXyl+OMLKYnkPpe0y6QknbjrElKSV9w9zrMpKdwJB3J8XlKmr17Pu7dZEe+E25WDbxWK3IPIs9cYjCNspAQ2UgLb35Qcx8d/wNtHSqpX4KV9wPCVt4GfZqTkffZpF6rlUjhbLcueS9oDXyVDWYk1DKVEWVPNK0wnS3oyJVjVVEqqaxRlF6RWfTbWvSA1r2rF3bEGDilspAQ2UgJb7pRQXxJjnd4+atX8LNLbN7KM2xbp7VOSQVDmLdLbR0pcLdLbR0pcLdLbR0pcLdLbR0pcLdLbxz2OK8fnJYXevlXkHkSevcZgHGEjJbCREtj+T0lV26yf0KlJ2835prGIy909Sck25JQM7UlKtiGkRCyEHqytV+qrkddHSsRjLC7rP9J+sRh7Limd+aC3mbgj00lq9nWJcibSt1e2QS5GSjjjoLTPS4QtmrOGeB7pnVk43SyAowcbKYGNlMCWOyXUl8RwrFWjt28ZcXWvt1H3+nVxNfS3UUP/de79OJHf2yf+ESmZJ49gut4+ZT0pmec+l7TLfCNbOnHXJd4pGZ9dcFXcPQ69fXk5Pi8pgb19xydxG9yWexB59hqDcYSNlMBGSmCTa+g5oeOsrns9vwIv7bOpr7wN/DQjJVV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EgJbOfTMOXNkH2kpHoFXuzqaMBISVsF3ZZDVxuTs/UMdVq00WmX6bRY2FBKlDVtmwXTyXqeTAlWNZWSg96+PVQfbtHbBwGHFDZSAhspgS13Sp76rJ+aAZ1jrVpwb99krRpBUcTVvd42kpLxGrN7e20urob+tpEa+vmUmDvuzL0fJ6a3j5S4ksclXW8fKXHlPpe0y6QknbjrElKSV9w9jmtvn7gs3hhzj3OD4/OS8u3ePqWBj+cll+QeGp69xmB0YCMlsJES2N63AxfKm6lJ2835jqCIy909Sck25JQM7UlKtiGkRCyEHqytV+qrkddHSsRjLC7rP4qBIyh52XNJ6cwHvc3EHZlOUrOvS5Qzkb69sg1yMVLCGQelfV4ibNGcNcTzSO/MwulmARw92EgJbKQEttwp+VuW9u9x/Dv0/yJuSX2JzrFWLbq3bywlvS0JiiKu7vW2obrXuYgUUqKKq6G/bfz7cSYRlJ6pTPxOb1/P6ypk9JKFlHTI45Kut090DsdIUEhJj/tc0i6HpeT/LYenE1LSE3dd8pWUvMNBSmbE3eMEfG9fvcGVMw4RUTg+LymxvX2i9+nGPOmQEkXuoaG3LwajAxspgY2UwCbX0HOaxlld93p+BV7aSouvvA38NCMlVUX0eaFaLoWz1bLsuUTv16KpYgdDKVHWiJ0WpGQxT6YEq5pKSXWNouyC1D4LjPnePkg4pLCREthICWy5U6L/I+P8S+JPWae3T1wzvhkUi/T29daMbwbFUr19kyvR496PE9nbR0qcyIOVtLePlDhxn0vaZVKSTtx1CSnJK+4eJ6C3j3scJ47PS0p4bx8pcZJ7vHj2GoMhg42UwEZKYHufwi+UN1OTtpu/h/pq4Sop2YeckqE9Sck2hJSIhdCDtfVKfTXy+kiJeIzFZf1H2i8WY88lpTMf9DYTd2Q6Sc2+LlHORPr2yjbIxUgJZxyU9nmJsAXf27c9jh5spAQ2r5S0H9kjr/8APGRWZvcSF6IAAAAASUVORK5CYII=" alt="" />

  在2.7中,能够将几乎所有的数据类型都转换为布尔值表示。其布尔值的的转换关系参照我在布尔值篇的说明。

  python在2.2中对类型和类进行了整合,以上所有的内建函数都转变成工厂函数。所谓的工厂函数就是值这些函数都是类对象,而调用它们的时候,都得到一个类的实例。

  但是在使用上和函数也没什么区别。

1. bool(obj)

  返回obj对象的布尔值,也就是 obj.__nonzero__()方法的返回值。没有__nonzero__()方法的对象的默认值是 True。

class Text():
" 自定义布尔值测试类 "
def __init__(self,value):
self.value = value def __nonzero__(self):
return False a = Text(123) #实例化
print bool(a) #判断该实例的布尔值

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYcAAAAhCAIAAAC9TvBuAAACdElEQVR4nO3bz5GbMBiH4a8slZBGrDKggujmWzrgGt1ycBVc1IGbUA4gEEIoeJf1fEneZ3Z2bEboD2J+FhpbYsvTmU6kFxn8enC0m7eJH8SO6ynmEXYFjHtWKrdjjKOV9NoPa4vhYaQTubsQa2V+fJuOTH9ri+0eTgXuxnQivfWbAlf3cPhZ7cx8VlazeYT59FR4U6bqxOz4YT8Rwd2nK5bGvtSTtZW3Po+lF+mz67M7q2xrGk5+ZQY/FZNe7GClE/NdpLd2WP4b98ybs/7gqpZlDkaRz2B9FKk/ZriZLvU/n/f8atxdiPV6atfZ28HHp/dZW+Wcjs6NbnMfbu/Moz5v7rqDqd/fP6m2yiTWZ7BWpqz54O79ZM1lyY8bbXmZNrytJcVbLT2sx5aCHl7r6Uxn3zSkd7alzYVjP/hAPSM8zIfPjfErZ/Dlmi9MpSPzZ52eW9bbYjWnrof4P+3uzDPSWrK5Jvi7vCGVAOAFpBIAXUglALqQSgB0IZUA6EIqAdCFVAKgC6kEQJfPplJwRkRE+AYigGu0UslbWbVix1tSCcBF2mulJW6CuzV/4kYqAbjImVTyVqz3/jh3SCUAl/ljKpXPb2kjKc+hMpXWRz+TVljzaeaf+QEhgC9yeq20ORJj/WD1bYwxODPlkbfkEoCmk/tK22PlAmpfbCq0JFC+b86zHoCWV1MpHQnOHK+V3JxG2Wa5SQkVAmslAA2tVJp3kIpnrnkZdLsZEeN+pW2mrGBYjy1hVduOAoA9vtsNQBdSCYAupBIAXUglALqQSgB0IZUA6EIqAdCFVAKgC6kEQBdSCYAupBIAXUglALqQSgB0+Q0/lPzztzg3eAAAAABJRU5ErkJggg==" alt="" />

2. int(obj, base=10)

  返回一个字符串或数值对象的整数表示。但参数为字符串的时候,可以使用base指定进制,默认是10进制,当obj为数字的时候,即数字间进行类型转换的时候,该参数不可用。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALoAAACcCAIAAABHmSaNAAAFBklEQVR4nO2dUXakIBBF3fVsI+vIJp0PMqYHCuXZQlPFvScftrFbWu9BJPXitgM0s326AQLb9kxrn/qcBfnvwP2xjmP7yhO+ti9p+5LyHDee9e0fN94LGflR62dMCydWlee75ZS/blNbhnbekuNxY2q6mGf3HV0a3w4Z9iF70Jiv7Sv9ZGteF143yzb+aSW6zEH1kD3bx2QGZKLUNvttJbrMQffeJVHqcrn8XyvRZQ4GjV3QJQaD7oxUXVqGLy33StwZPUv3eZdyDFtbft3eaKglR2ZArRNi3uUpPB01ZnU/DgcOBNAFBNAFBMyx4fhmgA/KO090gSr0LiCALiCALiCALiCALiCALiBg30hjDJjgBQigCwigCwh40uWoU9m+t+37fsvffLuwo3BjQK8pxtr5LtcnObL17+tiFnqGL9tzmWI8ceVEi2P5EVdOtAhcFOw4xWhv2aDLIzTqUr50jeMUowm6dMVxitHeEl160r13SfSIpdlboktPBo1d0CUGg+6MeqQYTW7r0vgPY2rtWfHOyFGK0aQ2xdI4Lyf0YZUpluXmXWam66Hv8eHBXNl96QIfB11AAF1AwNClvOBSYgeJ8s+quRavLzFmca57F3SBA3QBAXQBAXQBAXQBAXQBAftGujSGeRfYmdUFCXQBAXQBAU+6zJxijFfaYtK9mi4RLMW4QuGcyaBa3UZcpBgXKcs1GZQEaMRFEmCRon8T++uRYjzbBbqUkGI824s1dtmX1YUU49ku6F1eIcV4sQt0OSDFeL0L7owSpBgvtzm2ZN5ldmZOMa7gyu5LF/g46AIC6AICT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7uLBTDFaorXJf848mvbV/+ddX7aAprrFxmXC+Z5nGN8vXj/bHZS3ogPU+vMBjH80LDCyS2KJtPeeD0S6+YlZhAv9qK4VInmDk65hAr4VJ5ZvFEYH/8EQq7p7STcDhofoy7r3Mm3Ku2r75eSgUS8/QKlRLFIWr7+nvQb1HbYE71zII5antOHrV9vTK9H8iN3qfN0V1CbfVeSgUS8/QKxVM8rnv+61pq25RCPboptXFJs+e9KEr11ORSwhWqK1yX/ONJqu3rf/XcdjcC55K95f5gb2x6M8vN0GZKiqVC0EYvXK2X4q4zmxBHiet2dp047nGetehK25tjZPqsnSFvS3HUvCmQGmKv/DwcpqXSIrG63ktxoIHJrwDfJYOvZ6+DAJeB2gIAzGCS2m7btrFwAIAv5j/NPbHm4ekwTAAAAABJRU5ErkJggg==" alt="" />

  非数字字符串报错。

3. long(obj, base=10)

  返回一个字符或数据对象的长整数表示。其他同上。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAK8AAAA3CAIAAAD1xY0MAAACHElEQVR4nO2bW3LDIAwAuXWv0XPkkvTDU5SAINhgbMm7kw+buAlBW16DQgT4J1xdgVFCaP2E9ruQ8dFYP1rb9Req/Ibf7XWgcl8pg91TAjXyljpDiBjjGhtCCNgwwlDsd/UQu6rVgxrm/kIo0ZtpuhClDdkIkq7LYSU9mZVjw3SqzTRXiDLA5XUmR+0igQ3TuaZvqNnQKMSGBVwzb+i3IWpjxwY2TOeaNcWBvkGFFeZc1u03ZP/i6izyfSKpvpXXXlthloWdVYW7t1Rt+EiwFzkRA4116m4mvGPABlgGNoCgrsc+rrcXPIFyPZbHHhWew5e+obwFx2ADCNgAAjaAgA0g7LMBM3yjrzBT1NMtGw9PgPCCgA0gYAMI5m1IJxjCK4TX8Z8z+Of6Z1qbZ7nKtaqFsyzfYp+V77KhdgDT9MkrP7lWDRUaUU/Xe1VoHMD8qJVpG6LxXCv9yQ4bBr+9URlDQnjLtVJZZoP1RFBvuVYqa2xQR4ry9s5c0zecl2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b3K641exxd9AkAMIClNHr338Qo+ilwNhAaDQBzsJRGx1KYFcpBax0INAAM46H3o+M/OnP+GHx1dV6RQPaZoeITAGAMS/3OMFve3i+XCDQAjGQpjd7500gA8C1W02gAgC+BRgNYVL/kAzEj7oNffW/taHTw1M7w0bD+kDzEm2qg+yZT8bQzOyCNT1AbKZ2yvvM79IAJXj3q4tA00N8fvfk0MX+O0JKG/ni/r8818evoovfPRJvsju8d6D+MePO69N3wvlS/mX5n9Ea3I6KYwle97zjMV55aMhnRzVfrxmQa/XrQ6Eeit/sccXteHeLZOvq2oupTyuATrkcfax1Jo3kbkszcuW66fmVOs+nBdKX49CwVRIeejenBTCAw028nsz7P3kRjr3cVytIleuDcC5d1GGSlBDLjHpZJXGU69I7r4+kZ60fXbh1g2e0K4oEyLRsjLkKhRgdTokyk1xjMxDUl/YhpP2i80NkeBU6UQLF9vLvXGLfEQ1fao9J8qidOPOqCiROvOvpEXM8aMYqZZxAo2W5sFMNV7K4wLvn1Ka+jd/9y7X005Th7tlRIT9/5q77qHB+zo6QH0vP0GoN53C71ixdI7FFpPtUT11IZKIkVZdWu0WK4oqPOnDJz3pVwRXmW4inDHs7X26la60g2sh/j8Q0UQWl8VqP3tlEqCiTm6TWKYpR1+A6N3i3xChJYQqPFC0/pqXGPRseXTzTa/16enkCk9EHPTv8SGq2PUlEgMU+vUTwH4n2v3y6q0boIFqVkCnTckp2OOL2Kk6vxABuh0eOSX59Cjd7/19ztdFdybTlbnjfOxqY3s90MbaakWCoEffTC1Y1SPHRmF+Io8b6NQyfOe5xnXXSx71efwcQFgeoOm8NSnEoxTzNKxRyZlkqPxN31UYoDdUz+FfA7Q/gkiYwGBp/RApgTNBq+ysfKMVgUNBoAYF7QaACAefkPu8IXKLaUl84AAAAASUVORK5CYII=" alt="" />

  非数字字符串报错。

4. float(obj)

  返回一个字符串或数据对象的浮点数表示。没有进制参数可选。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJQAAAA3CAIAAABl1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CYGWpDjYojxLNgzq9rikjQUG3VfDd3jw9gALEcw27QhfAZbLKPAIUpvXgcx8H4AIA5/AGO8QYbDhCfwAAAAABJRU5ErkJggg==" alt="" />

  非数字字符串报错。

5. complex(str) / complex(real[, imag=0])

   返回一个字符串的复数表示,或者根据给定的实数(real)及一个可选的虚数部分(imag)生成一个复数对象。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANsAAABsCAIAAABsLlDaAAAFjklEQVR4nO2cYXLjIAxGfeu9Rs/RS7I/ts06RgIJAZHQ96bTSQgWjv0GG4J1lXeu6+dvVmFdp7E5ADAC+AJGAl/ASOCL7EZev3ey1/d1fU8+GmTMC/fOTd6Ozh/qYMkLt/F1ff37M8Z5yMEZSVj1fdW2cYXddsGd56GJImUpZa6RDR0bkr1edwu5dsEDk38f7yktm8u1kBjZqG9sPRv0cZkr5esie3foUXKv0y68R+Aaqt/WEYaN7H4EIy2wx2WWlA8Lu4X3/1zN7tt681pfu5Hc/aUoJoxkWN5HktfWRUY2OuN6H4xGajvO4dazsfw+cqeR3A5MN7LtHIy0sHys7faqXcRaDI+12YDQkWfHfCQ5NCFHIeVm5P0FNyqSjJa4HSgyM+pZxlcJV96PCSN5vB8a+6Rjm/1yQMc2ro/OrN9mQCBcGwkSwk9h+HDVyW6AbXA/vIpKhAvLuSYay8vbTYODERlJmle/Jgu7b7vCwchUkGulqHpKpSYaKawDzmDQSG19oZHcpRxG5sFqJHd/eX/9+Cu9PhJGZsZkpLzjVF21YWRmxo1sWwIjwRiDsz9Lx9qY/cmMYvaHHIJw5f2GMR8JKDz+ZqOdGwIn4eiEy/tXcDA4/8AX2Y1cmtNiGyclz9ixhnw6gXJasE2bY56aPOO5x1GkLBFyWnCR7THrgHT5p8/RACb/Pt5TWjbfltNCW2c4KwFJOCnp3UVOi7eatpwWUx73HnvErBxjZEFOi3vNoZwWj0cW6wcXB2JK9upZ7QwjkdPiraatk5Nvruo4ExmJnBbPmracFkL5tGOXLEYipwVRbfZY2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2ecncM95V6H/40EN8kqt91qj+bxb2XKouXrbxEz6aXU0R/h0tJDALwitfBe/GLlUq1knJuDeooHntTXszWEIeiWLxukKz3jrrHjoKJoHRlKqR90NQqmPnB47WVzcSg4+uQFEdecZFU8GfVULNaSRE7LzHIE7dS4L1pOXCkh+Tl7G7kZorSIIr38bp7/av0eyFnQWz7I++tTn9V8R5NYWo2qDgzUx0v0nQ9Ua3iFTUbWIzpyLPWp1anH7wYkufCHI3KUGymKA1Sd3Ewkk07tdnB1Whw5dsZWa1EcWkuPl7BOP15auUFMF2t9EmVlZtUejMkL1s9GvV17g618uIMMsRFFLNiWWXl25mxFgkem4tPSm7Wq5US/BS1EtdDUe+CUsrk1NFHiBiSl7O7kZspg2rVsbdqeldMde8P9kdeIY9qD1ynXHNeP1wzm9bMdNO1GZKSU0RxdK1gXd8gJDO9tlkHUFeho0ZxnIHrpsHApm7BzHNWjdysUTMkZdgo3rM1CkIqXHg5g4rXgendsQ+PqsyHuXtkXAfifcZvsg8reWhvPqcmH+YBS9kDqgA/PLE3763McRzHs9oLAD4FagUAe/AvCYDR4zIEvlAAAAAASUVORK5CYII=" alt="" />

  非数字字符串报错。


内置功能函数:

1. abs(num)

  num表示参数必须是个数字,下面不再重复说明。

  abs()返回给定参数的绝对值。如果参数是一个复数, 那么就返回 math.sqrt(num.real2  + num.imag2)。

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOcAAABsCAIAAAAe4TJsAAAELklEQVR4nO2cQZLjIAxFfeu5RrZ9Ws+ie1IZWwgJA82336teJCosnMprgrHR9vX1tUNHtm1S/hEdfeYc/UEusGFtT7bt508XhY+AtaCHpLXbyJFgaHLogm3tH+ubiweDvLbXa3tljwpadW62/SMSzJ4VzKQ41k4TN3tIRClfxPdrMxjsAn4Rb4YwQdystXGfrlib6gjmU5nX9hX3e0rwaeo7ctC3FMda2CNXY73EPciaDf6c7v+eHSi1PB/oBM23sBRTx9r9NNyWBC1dqDHWwj55XnuW1RlWzQjW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xMiJGrP+Nc3ZuPS1PAw+QsefiWY6mgvT2rjvTcfDlW4NwZ6YC3oMcNanquCvmAt6PEXH1o822EK5tsAAAAASUVORK5CYII=" alt="" />

  

2. coerce(num1, num2)

   将num1和num2转换为同一类型,然后以一个  元组的形式返回。

  转换规则:

  1.如果有一个操作数是复数, 另一个操作数被转换为复数。

  2.否则,如果有一个操作数是浮点数, 另一个操作数被转换为浮点数。

  3.否则, 如果有一个操作数是长整数,则另一个操作数被转换为长整数。

  4.否则,两者必然都是普通整数,无须类型转换。

  优先级:复数 > 浮点数 > 长整形 > 整数

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALUAAABtCAIAAABoXLe8AAAFPUlEQVR4nO2dXa7cIAyFs+tu4+6YPowUoWAbg21+z6d56HgAGzghITXtkwDgeWYHAJbmOn08z11dNvaXqPyPalFvXJlysPTDx5V0FxwZ5A9N3bKkJUK65qkSKQeOHDtuhgIj4x3lX+UYuJL++kgnSkQphSZjBO76qFaU2hR+85XI3/P3fkojWfJjyf/Q2mYK0Id+2W9iG30kP4l85q/VmApltFZPill/KOTqgl1A8FI2uK4+HNeP8mpO/ARzq4KyTbJ6Cru/XLp+uN9cZCO5AMgtVNv8AH30BENa3R9OXe4v3W2+kM8QZbTd+nB5HNHog3Q0aP8StHNRPoqSRu6WoTf+KIdeOaNCSa8rVXBEPgxxwVQfaNri6a65KaG3A/fG7Vj16hXHbejXnq05vHvASEUf5OURes04Nr7ItT1+DB2R90sqo76rXMmP3WXslI2Q3fl9NHW5kpoebSERqz6UAySUVPptRT/BXC15joWSymD21oe+S0aj3ruebkdB+uDKrC+Ryfrgluh99dHUo+v08Y5O/pGrk3ZHfQjxlI7KaLkeyf2CPtyMpH3f9UNv4YxLAX2wX6GPFLe/tejDsvep+tK7dtTHpuJIXvtb5QM8VzJiNLtDWrZHU6jEOKZj1WfYPo8TJyCoR+OZGab+St2FA3s0OwCwNNfp4+C/kY/oGtHieSdfXjT5hZ/EjtA8j6p3ua5vq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BZvyHwCn+xR1smYvAAAAAElFTkSuQmCC" alt="" />

  

3. divmod(num1, num2)

  除法-取余运算的结合。返回一个元组(num1 / num2, num1 %  num2)。对浮点数和复数的商进行下舍入(复数仅取实数部分的商)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANAAAABTCAIAAABh4h5VAAAD9UlEQVR4nO2b0XKsIAxA/ev+xv4xfbB3rysJhCCRlXOm09lmQUTPgFCzJYBAtrtPANZiIeG2bWBnhx78SXxcph/pqtmDZV7b67W9TpHWg/gaSpIQYmSn2oRYEucsnK/RaOdaq/ioClfWpayOVhLhLHTp1ercXcKJKriFMx4EROQLdK1z+xx3nOlOf6ZsHjxWyQuLRxAb2kG4eVAv0FXOnTTSvtJK7h+Ov8slxSOPEE582kO4KsNHuKcKVz0IiAx/hrMLlzKxEsI9juGr1BmES4ZtEVG46rzJKrWViH24/Nm/vBo4VUwH4QrLjvJhxW0RYzDvEftwbha6Rg4h3HMraHCZIBSEg1BU4YZOEcw/yyLf+ZMQ2/b3428mq4tza1IXTvvc0IYkK8Ktibjm10t7LREr4tyCIByEYhXu8mc4LQjPhhEOQkE4CMW5Sm2dYVmlwo5/H85uTGd1eBLO/zR06oJty8Kdh1AQDkJZSLhJXlmb5DTuIuKN350nZd6L1bVivBt8ZHhOw5FnZN6L1bVivuM/mOFZW0eelHnfKg2D3I7cbTLvq51COB9qt8m8L9OUX0OO/pvhIxzCVZtbiuHPcDMkQiPcPAxfpc4gXDJsi9gz77Xq5OhbiNiH+97Me004cvTdLNTzobeZHH0jS3ce4kE4CMX5Phw8ich77X/jV6vY+vZ5uemmhggab5xYMoa6cNpne62GszFrnX8maAlaCgxFXMnrpQcLZ6w44Y38xuCJGOcQbsWgNs8GYBXOMtlNItzxVAnmQW20m0u46lenb+OFS4erSVALFu4RwvkbIqgFZxQu6acljsyOkqUTyq6CvSHLtwSrn4dSFy79u+viWJ1XzL+yd6a/IdFOgnnwluEtacJdeAZhPQE3kfcIHSAUhINQFhJukhfRJjmNu/jo/OKZ9xrGt8y1Mrzxe+Tc82Uz78VihZIWyGnI6dLrSZn3rcFWGOR25G4vmHnfFBQnyjIIt6N2e6nM+02iXL0Qz4v1PEE+jOEj3FcI5wgW4pbCCPefNTPvW4OFuKUwwv2xbOZ9azBJk3K5QPWAKxCxD/ctmfcihZJk3jtYqOeX32bfoLWybWkp4a7CsScCb7hqEMrw9+HqZzCyIfHgjE03oq2/zn+K747mJZubl95HddcV4zg3FXXhtM/XNC+ZXS1WKGmpqwUhAHElr/557X2yq9ApDc7Ng1+4wjxrbftq4bRTQrh56B3hhgr3Fuj4U20a4WZmauEcQTGOcPOAcBBK7yo1nwHbmu+Qg22Rb+TifbhO4ewLkc5TQri76P1PQ/+mydC9PWybDee1798TuZwJTwlyuD8QCsJBKB/CDc2CBkj5CIdzMJRfEafhhyTc94gAAAAASUVORK5CYII=" alt="" />

  

4. pow(num1, num2, mod=1)

  取 num1 的 num2 次方,如果提供 mod 参数,则计算结果再对 mod 进行取余运算 。

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIwAAAAzCAIAAADKPnfJAAABoElEQVR4nO2aWxKDIAxF2XW30V9XSz9qWzoSCO9cuWecjloijmewKcQdx+EvPJxrOTkU99+j+6AJvLbUBC7HRSV5w57Cxyrt94oygijJm/SUGAd1krKBFkhJ8v08Pd0z3KJfhYfvnfDwvF25F/2zvpsk39XTdT9xMvz83a7QRbWhothVTBpJfqSkFkNF4auY95s0SFKjoaIrrGJedqeX5AVD5x3n8rRoRn7D7G5EXqdMHL4nvU5SSLRNaUuD5BOHXkSfeB36bLvlOnaYJCk6XIiSeSOJVENJAGQkgby0bw4lAZCS5BwlmUCU9NZDSRagJADikr5uKMkCoqRwI2thdgdAPrujp+VwxgEASgKAkgCAlDR/HWjtytO8ldle9K1g1bdc6Gn3CtZe1x8KK1gru5sJK1gLWhqV5DeoYJWa2al1ZQVrQXuLkjapYNWHmJO0QwUrSq0rK1jj70+M/0ndga5gtTjj0B1WsLYAOXe3G5QEQGZlllggVdJFSUbgSAKAkgCgJAAoCQBKAoCSAMik4PRkAc44AEBJAMyQpKx2IxIvmqHmKK3B1t4AAAAASUVORK5CYII=" alt="" />

  

5. round(flt, ndig=0)

  接受一个浮点数 flt 并对其四舍五入,保存 ndig 位小数。 若不提供 ndig 参数,则默认小数点后0位。(整数也可以,不过并没有什么实际意义)

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALkAAAA9CAIAAAB+7l/FAAAC9klEQVR4nO2dUXLDIAxEOUZu2mvkN6elH54yDpaWJRYuOPumH0SVBTFbQT1onB6Px+v1ypCU8O8Nn5TefrpCiTlJnlbMCa4m3vNvxgH+YlpcreRsZwVzjo+ept1LNmIJkFaE2COtCBZpRbDcXyvpFjujGb6Fq5Ufa3C88Xqe6flMz8pY3eL0BxPQczvavV6qvszevSGZnsywx4HyyopyqSzVVJltEyApc7KBA+i9ObyuMY+msQatJZdKK+DmMvfdm3Imr+BoWAonhz2O9n4lUC5lmajWi+1jsZht79r95aO1slm61iDTB4up9NLs6GKove0Iuewtx7ZnPDqYnht8YjA5o5Vje9/AEfYOU21ZLs0r2dpSdGmFNG7E5hWwRpAdFRFgBYAMNLVWwvcrS2vFXFxMT9wRdlhSKyM2tr1aMdcd09MMzvyjQf6/A+y9axDpCdr/wqXPV7xNKDBWV1WWY1icWswtJ9jWmLIwIzQ7MvvychWTva5Hz23XYIZvcX+tiCikFcEirQiWvnNxbhQddfsC+s7b2iFoT7E01BokrYgsrQiehlaYXYi08iUorwgWaUWwBNQdSitfwti6Q3En9NxWsEgrgkVaESz318oMJz/+nZCboLpDlzNnKLtOu4EDeMw4zRGOOFanukMbMFXMyUh8VWk3h/fBBH/8lduRVXfY5ePlAObCYztKHx6xqUV1hy6eJrrWINMHi6n0EpAJLtZKVt3hu6UrrxyzRTMz7R1OblnwOLtjqu6Q9AHzR3ZU5g//uQduMi7NK6o73H80FxfTE3eEHZbUiuoOSXvvGkR6kuMEgwmUXb74+YrqDslcxWQvwMnL3bB6brsEsYvRh0FurxURhbQiWKQVwRJTd7g5M/aumGIqAuoOc0bT78WRXJYj4Bw/8En+y4OkleUYqJXNQq5NYn4C6g6Lp2nx8o1YjlF5pXz0NCSWY6BWkvUKMgllXfS+Q8Gi9x0KFj23FSzSimCRVgSLtCJY7lN3KEZzq7pDMZRf3YnaqkVRx4UAAAAASUVORK5CYII=" alt="" />

  

注意 int(), round(), math.floor(),这几个函数的区别:

  1.函数 int()直接截去小数部分。(返回值为整数)

  2.函数 floor()得到接近原数但小于原数的整数。(返回值为浮点数)

  3.函数 round()得到接近原数的整数。(返回值为浮点数)

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOIAAACTCAIAAAAcDFLkAAAHjklEQVR4nO2dbdLbKgxGvetuIzt2fyR1HZCEsIEgfM5k7hAijIyfio/XcLcdYHq2XzsAUAaZQgAiyXTbInmrscZdDOaryf5ILejPNHhtryr7nOTpbv+4UNbI12pJ6hJr11wSLT1uw0HaXv2U6sFQc6ISMa0VdMrUqSex9qJ7VT5Dwi1RNleqJlPjuXoeuaY2TzS1r2ar8KbbcCA3VkOlvrbX+5PknBNns8T442Vrmb5zqjp90cbW8VFLsSKwURurbUxNlJcIVDP776U7HDqL+2Wap88J+wpnA4and+geTd/kMi2mv7xsGk2NTtlZ0aE/W3xG3EWmVQwam84mU7E3Fy3timwDZNqKQTP9Wpnaw1OtL3bO6I382k7faWmkwcNXe3WKo8ncSEuf7QVHS4uUmkzFqGlcoViRWJcWoT0xG4pEaq81nu4adzEYmgwCgEwhAMgUApBPLD4fgHlIZqByGuC3GMvmI90AsECmEABxPRyNwlwQTSEAyBQCwEwfAsC6KQQAPUIAkCkEAJlCAJApBKD72/tHgTr7WTG2skA/Bu2FGkSHfwxVu0+hE4N2lg4CmS5K/336f7bPJ88554uZ9hXyhFj8G3v38znT2IW30/uPRW3oxjE1V17y38TGztx3WY6+aHrobD+FRv9m5UTKnhrhJv2j6T874etNmRZrURBlevwkxs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AJRn+uIYAJnCSMrrptpQlXVTGAYqgwAgUwgAMoUArCnTVm9q8sbnJHR/e78rDU89MV6qb+UtXGbEXqiutDr1pHZ3FIxkxM7SrrTaWXq5IAxAfgAPPPVE7PE9BWEA6gN42qknxvAAmf6c7tF0D3WchGiJTH/OiLFpCJkSTWdmxEw/xKkn19YHYAzd102jn3qCTGdgzWfAX6EWg8cAAUCmEABkCgHQ/pDtKMnb+zCKizJlLxSMhH36EABhy95ONIXJQKYQAHmfPjKFqUhlev5YxZApDKQ80+fUE/g56kzfPpwnNwPoByqDACBTCAAyhQCsKdOnvSe6/P12f3u/Kw1PPRHLGvlaLeJOAadLTj8fuMtgxF6orrQ69WQ3VSLqzDAwavds1bKdLKbXY8TO0q603QDt3+bfVqbXRPacgCrf2ANPPdFs3jlVnb5oY+v4qKVKak+X6f68U0+04n6Z5ulzwr7C2cA/PC06vwzdo+ke5DgJ0caQjrOiQ0925Ls2ynx0NH3mqSeizfaNbWlXZBsgU5sRM/0Qp57k9nZ+bafvtCz6WTX2XYave+PUE00Z4hWKFYl1aRHaE7NrLZdhzXtb45ld7v3XY/HbgzVAphAAZAoByKcLn4+rsGKW5FddEyAnmS3KabmkrjztOigVrmEshjsKSzZb9j+QrromQE5jmb5znIMBACfi6vH1sakhUzQKl2kZTY+vmnwBrtFYppt0aAoahZuUZ/rOGX3xOoY9gE153VSTqbYaukmHprB0CndAOBAAZAoBQKYQAGQKAfgLY76iHX3EnsQAAAAASUVORK5CYII=" alt="" />


仅用于整数的函数:

  除了适应于所有数值类型的内建函数之外,Python 还提供一些仅适用于整数的内建函数(标准整数和长整数)。

  这些函数分为两类,一类用于进制转换,另一类用于 ASCII 转换。

1.进制转换函数

   oct(num)

   将一个整数(任何规模的)转换成一个八进制字符串。其结果是一个有效的Python表达式。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXsAAACFCAIAAAA1s8+BAAAJYElEQVR4nO2da86kOAxF2fVso3fM/GhNiSG2c/Myr3PUalGpx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5z/BzmrZluDb3JUNTvF+2DxjjOk3FbOmcE90m16ZccbwsNpHCBnbczbNn+mvEoUpaTqtAM9+OSc014AelSmI89atxQGhyPYjsMOvurW2UEpNA+c6KVJH3Xv+umtHyOTQSkst1sbwsNZJoWKtabMO6XQyzxdCvWTvvTeJIVxhBOlMP7lWy2FIoNSmIoaDrx3nN5xSB4rpNDLjBQaiYO/paKX1uIiHcG31kmrd7N47LTsRwRSqB+OwcYzKIWzvA8W75NC/fReWnVLK+Tr1NCXwsMZaJTN3sx5FF39wxkClMVFm3HOKueCXlTnj2YApjv9LCnrRN93M7BMCuM98nbK3Mcg+GCPYkeBWdG1UksdwZcfzVqq2vTiTNZuKvWp7FTVZhD2YEN4Mu1Pm3Q3++/mfLqsM77IPsDrkaVw8EcYBqGqAVay4xnk4zgO2jAA3BikEADAkcL/LOXSE3MfSCEA3Jv/AaQWk2IVSmSHAAAAAElFTkSuQmCC" alt="" />

2.ASCII 转换函数

  Python 也提供了 ASCII(美国标准信息交换码)码与其序列值之间的转换函数。每个字符对应一个唯一的整数(0-255)。对所有使用 ASCII 表的计算机来说,这个数值是不变的。这保证了不同系统之间程序行为的一致性。

   chr(num)

  函数接受一个单字节整数值,返回一个字符串,其值为对应的字符。

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAL8AAABRCAIAAAAMxuCjAAACsUlEQVR4nO3cUXLrIAyFYXbdbWTH9CGtxwUBQkYETf9v7oMrx2mGOdcQD2rKfSn9/BsW4eHsoT70YyGESOlJ8/8FDZdA78/gfkljrS8qvdLrlV6zVxU5SL/qSl03f1T0lSO7LUCzl7QCcR0PX4DlHmXFHKDZ9NQ3ntYpZQVLyMO6NkDvqeo+Yb0Piins+rGe2kjPmZrDuipART6ugyJJdf3Pp2ykp1jiiC8WK1jC/d4jpkGMVOvFuRGId7FzW+oX8Zz7uscpPa1TpGcn9+9crZmr/wLhg46+Z+krWGXH8556yVwskItj5dJHeZshPX4ijSzPmk/D4MKO9MCuWExo9wIcvGsA+9RrTPWVpOffK+892suIDlj34AlVes7eHomPGSfiHhoChDttHLj9oKaduYoDIDNz4Ym5VTOTF+7IAuxID+xID+wipWfVZh02/awStZc0V9sL617Suq+0824wCNlLev+xs8e5VezUMSV8L6mhODwFpcC9pJ2Zq3Vh5z1hELWXtD9z9aez4SkohewlHd5dSM8eIXtJ9X+BhfS4it1LmmfSo1wPQS92L2m/mCqtd4NNpEHkWfNpGEfYkR7Y0UsKO20vaV0nPdD2khaniA7yVE8FiUGB9MCO9MBuriMHuBsngm5AtJAe2A3icJ+zmL9QIAuwIz2wIz2wi5Qe/lb8aXbsLSys6iWti60Nh7O/C0ru+5pFHulhC/N+7j0Vooe9pFdRmRgC5MS9nys79JJeFdLzWc1hPbmXNEvpyY11j3g5lnC/97h2A3Lv+Sz3dY9TeuouLdKzX8heUrHId679ovaSZmmVw/OezSKNLM+aT8Pgwo70wI5eUtipeknFXYWkB+NeUnFfM9FBZlc8niA9sCM9sCM9sCM9sCM9sFPFgS5SiEgE7EgP7EgP7EgP7L4BTtbER/iqv+wAAAAASUVORK5CYII=" alt="" />

   ord(chr)

  接受一个字符,返回其对应的整数值。是上面方法的逆运算。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAABWCAIAAACii/gBAAACgklEQVR4nO2dUXKDMAwFfeteI+fIJd2P0JQa2YjEFD1ld/rhCKZTvIPt4Me0VB+l2G24nAM2Sll+IBQIkQeF8qBQHj2F5Wc2LvdS7q6/3zyzZJnVjcv4sq7NX5zFrdxu5dYUm353KuydmcOifQ1xLDaVdae/6a/mVlhjWGwUntHjCSyOLmCuxcfAuLby/GjWtwOps7sfM593msytsM6z2BhatxtPvTOrr7vX5jwWkyuceBcOFDrPrEe6238jZlY4fRTdbe8e9Q+kTWN0claF09cyUxRWR48fGkgT+Kv/+b2wt5wxp8N3VjTPUXR3LE2rMDiz+j2Hv6qoEBpQKA8K5ek9PGw36J8VNu6jYT6/N9pkZ8LiVTiowLWgUJ6RQnPaQ2E0RsuZuhGGv4DsPkUcfYQI7AykvUMQh52BdFuHaOBEHhTKg0J59BSS5m7ImeY2hJHmPlScxctp7uYQae5XilN4J8FGFLhW5TR3ReETuTR3ReEa0TQ371QsiKa5eadigTS3EKnS3OshlDR3XEhzNyS5jE8GhfKgUJ7+Y0bS3CJ0gxe9BkRjJwo8LkIEugoHAymEwlY4HkixGIrD71T0inAVXoXchWFBoTyjNPf2hQqWMwFBiDwolAeF8ugpJM3dkDDNbe7Xk+Y+VpzFC2luMztDmvuV4hRIsHnIluZGYYtcmhuFf1BMc6PwF9LcKpDmlidVmns555P+w0GVfjoT5PdcTpLL+GRQKA8K5RkpZNdeAq9CsjNh6drYRoHNNlxON/5UuQtF8CqszIVRGeVIuQslsBVuX4JBYVhYkcqzsyI130+DUCBEHhTKc7rCUkqabZ2YoFCe03ftUXg2p2dnUHg233QmKsGiRHV5AAAAAElFTkSuQmCC" alt="" />

   unichr(num)

  接受Unicode码值,返回 其对应的Unicode字符。所接受的码值范围依赖于你的Python是构建于UCS‐2还是UCS‐4。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOAAAABTCAIAAAAJEZxtAAADgklEQVR4nO2d0XKtIAwA/ev+Rv/YPrRzrldCSDTEqLvTB4rgnHJ2EBDSZe2zLOM0wFS6ri3L34+SAzAbdIPSICiUBkGhNK8TdAkaREfdB3SEVv6Smt6eGcL38j0sMCzT0lol5vxiyfR+APAiN3EFR4ecF1R37pMWM9u7wQy6TVzfUa+gok8WQY3lYQZa+0Y5un0cf9JtYlugle+Tv71Vr3qbv9qE85ZH0NkM2jfQ0Tbd2iaW91bvDU9dgvbGpsbqEEVGD7r2DRMLDH/Vq/ce/XZB7d0qgs4maQx6I0F15xA0maRZvOW5LJZXSnoFXQ06MouvRt466G76sp3xiGl98mSpLvy1o9XN5X+Uku3dYAava2LeJN0LWhlKg6BQGqug+lbl7VU2NUMgDpV0QY0lAVw4elDjVeyEQKKmtCG3AdjTLlwfGU0iKExCfPsnp7u3wE6YRoCg9mIAXhAUSqMJyhgULqe3XffPOaOjCAqTCFtmwlGYAVpBaRAUSvM6QdkPei/ydtS7yIksYg8i0tYVcyCcpDNJMzgpqPf4EYJeQtKpzhmERBbZXVLOxHkPKEMIGefiK0cWUS4haAUG7fuGyCJnzssj6GwyetC1cOAG8VJIDBIIIWkMeiNB7dGa9HtCCEmz+IKRRVyz+PZXMQfCyVsHJbIIHOB1TcybpHtBK0NpEBRK4zgXX+2ZVvAjQTiOb7i1weXH0vlXn72bWEoi6ONx9KDGzGH1XdooaFsSO9/A2S/5wKk6i2euvhYeTLv47DvVqfRzu7RSRbwngsIaci5eEQ5B4STlBBWr2D8MPIwAQZUqxwTd/igl4Q1ogtoXGntSHnvE9/IR9IX0tpb9Gwgec7St3usUexP2XX6vJDybsC8cdWAGaAWlQVAozesEPbCPk62fF5K3o95FTmQRMZPN86WQ272Co0NmCGpJQybddq/vaEhkkfbsUa88jl6C1uiPjyzym4OglRk0+rMji7SCrp0xqFgdEsjoQdeSgRssEe2U6pBD0hi0pqDtEXgErUbSLL5gZBExk1l8NfLWQQtGFlmlESfroKV4XbvzJule0PRQGgSF0lgFde1c5pEIUThUErXj8BBMxdGD6pni8SOAk5yySTkKBxBCuy7oONWJoDAb8c2KnD5TEuAYCAqlQVAojSYoY1C4HFmrxRxZhIAfMBXMgtIgKJRmuqDi+R4AIz8slDXINwb3OQAAAABJRU5ErkJggg==" alt="" />


随机数的实现:

  随机数的实现需要依靠 random 模块。

  该模块包含多个伪随机数发生器,它们均以当前的时间戳为随机数种子。这样只要载入这个模块就能随时开始工作。下面列出了该模块中常用的函数:

   random.randrange()

  它接受和 range() 函数一样的参数, 随机返回 range([start,]stop[,step]) 结果的一项。

import random
print random.randrange(10)
print random.randrange(10)
print random.randrange(1, 10, 2)
print random.randrange(1, 10, 2)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANkAAABsCAIAAABo24DnAAAFDklEQVR4nO3dz3HyOBzGcZWlErYR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ytd66+WGxhY8mzuEt/F3tpPj/q+t3XwPMnqXK4J8AFvOorBYi4vVoSEEWIQVZhBRkEVKQRUhBFiEFWYQUZBFSkEVIEbLojAp4TQJDxPcvav/6sjOkEUPE9y+GLK7O6CdvewCOEveLcZFmUsQYab+4ZXDJZkjgk+J+Mfu4ElMjRohZDAFcrCaLGCGs0YvVfr/IEo0xuNYNKcgipCCLkIIsQgqyCCnIIqQgi5CCLEIKsggpyCKkIIuQImYxvSDNK9IYIr2X1oYPGTjepYMR6jV6sZYoYogqi3F2BD6tzCJRxDhFFsOHXoAB8izySReMRBYhBde6IQVZhBRkEVKQRUhBFiEFWYQUZBFSkEVIQRYhBVmEFGQRUsTf160SPmOAEXwWnSN+GIwsQoqwRp9O/F5ajBXmRZv+vAtpxBDt82jeUYsxwt8x0MyLGKz925QkEWNwrRtSkEVIQRYhBVmEFGQRUpBFSEEWIQVZhBRkEVKQRUhBFiEFvwsUUlTvjSCLGIbfBQopyCKkIIuQgixCCrIIKdrPGJBHjMG1bkhBFiEFWYQUZBFSkEVIQRYhBVmEFGQRUpBFSEEWIQVZhBRkEVKQRUhBFiEFWYQUZBFS/AdM5s10hIqJEgAAAABJRU5ErkJggg==" alt="" />

   random.uniform(a, b)

  几乎和 randint(a, b)一样,不过它返回的是二者之间的一个浮点数(不包括范围上限)。

import random
print random.randint(1,10)
print random.randint(1,10)
print random.uniform(1,10)
print random.uniform(0.1,0.9)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQEAAABrCAIAAAD4lqAiAAAHRUlEQVR4nO2dQZLjKBBF81gcYS5ijmGfoNl5MzM30NbsfQovWjH7Cl9Cs5AQCaQsJEuuLuV/0dFRpUogBXxAmLToPwB0Q9/tAADfDP0NgG7o6+urA0Ax0ADQDjQAtLO1Btq7Mff23Vwels5Ejd/Co5w/38PP4BvaoB42KevpzOvKfNj5qq6xkVmkgd7XC9GF7GPa5urY7XobktDFLvBx1S21d0PntCzm89AMuYdrWV/p+1DTOomx9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AdaABoBxoA2oEGgHagAaAdaABoBxoA2oEGgHagAaAdaABoBxoA2oEGgHagAaAdaABo539ea+oj5th5UAAAAABJRU5ErkJggg==" alt="" />

  

   random.random()

   类似uniform() 只不过下限恒等于 0.0,上限恒等于 1.0。

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAAAuCAIAAAAgF4XSAAACiklEQVR4nO2aWXLDIAyGOUZumrPktOpDkwzVhmxAAqp/PB4sC5D5zOKlPB6P1+sFqUNVEvDZSsCHKwEfLhHws5Qeo6bnRf8dVEopV9vBRVoPnsjYQe630X6AYWvGCRgALHPwSMbP8t6opbazRr0EmmCzE32HVjTGlo90t9qzmZ26Oci0yBrcjykztEc+uhGAB2nuwSwzmkbAdE/JWO995NuDP37MYSfgZi2ypOamvZBm2R7wlDl4B8D9nZU1rgV41grLGbBhGlYsxwKe1XfR8qdOoMNLiyxpGrYtsvSlE/KxLKDYQ6gAuzFe9U3WiS9DQrQkYNsTTsqiJQGnxikBryJ2jTag2ICPDd3yXKQY1RkSXeJ1R/QpatOPDasBhr6QYgDDwoxPAqy/aemU66tK9CiJ7OxTo/J4qmenbsuGFAwY5jCuLTSNWkf3lIz1fuWQggGPHaWluOktT7PMAxwbUiTg4XOwfjHrAPYMKQzwjBWWPgNNbU12/osNSYphFF1QAE+ii8Y9akc+dJykhbCHULUmSqwTUl2dctijfJO1igo3AAwoNgGfrQR8uBLw4dIAl/LeGkWUPxs6ZS+zNkplKpamp6cRyLWzcSpNN0oiYNRYWhGCp85bbxHLHdDjOdUI5mu3N/JtDQCsuNkB0/5nrKsTcLPMe4ClKiwBj9USgH/T0sCr13XJUwm16ZmABwNWCjF6SmeledQS5+05WLdvANgSt94J+luk2Ye+JKJ6sDNdWAQwHWY7h9NmzAnYOrix/pLxxnAK49rdfk/8C8DAzS6XAF+dsdi6LNmVvJb4eyq6cZlUYYBTBygBHy4nwOy32JSDEvDhcvqjIwFHyemfrAQcJae/KhNwlH4A7vqKJbQnhgoAAAAASUVORK5CYII=" alt="" />

   random.choice(seq)

   随机返回给定序列的一个元素。

import random
a = [1, 2, 3]
print random.choice(a)
print random.choice(a)
print random.choice(a)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAARgAAABUCAIAAADWAb94AAAFA0lEQVR4nO3czXWkOBiFYYWlECYRKwwqgmFXq5kM2Fp7omBDBpWEeoEE+gW55sPtmXmf08en7RZCSFwkKNPK1b1GPSj1UOqhzNIu8xzX43trwibqYWxjo4rFqOkLxTfrrNWQ7itqs57XWgvf9VYLb9QzOklhY/3oGOvW8dm34ZsNC8PR6rTzznyNH/PViPWU+W6q+tN1fOrx5ZxzbjG62eiomPOFtz5aZ3165q3jHP3rG6dp1JV2Un7zZQxttqG6ooW9/nELb9Q5Op6dwmVlP4rbDufYl7/S1a6n39SZ6Qjeu5VrBSm+kEdVF12wzjoZyM4gZfW80bPxJvnmSV/kLXyj/vdaeJ9X7+j4wuUUcdPhxPtyzk7KTKYy731PZ763l7fb9qoHqb86a+KrzmKS5Zb/1tht3ngoNX36v2x/jnEdx6dSj2P28Cu37YzZ6inKbAWLWXFMC8QttGZQajJmCPV8RwsTla2e4+o3t5Uypa8MdjxF1IJ0rMbTmcTvPfSJ9T9sb5Xva+v216ijpm616adW01/jU6mn1oPS04cefI/tuzsaXPRqXqbWnnQEPxtH4Ze4+61BZdy7esNvW+3/rw3VcdUpx/hYe9ixHNGjv8Jpvf08XHSP+aQs4/siP2vtnJ9/eQsHY9Oa72xhap9M9p1up1q86C/LZPqDlE4RlSCVVZV7X4waVHXdcbYvX481ISRxj6np0y3GX0G2r631RbVXe9YLlXoaR3FSc32UVT4ur1EP10s7t75Ol0Znqyy3n+t2qo1o65B6/hIP0sGa8z6t1HNfC2t9NeTXPH9KnZeJvXpHJ50i2qdOPPuVe2+dpumcWdlXNmsle//038Zfs0aet7m4XudzeEfYjimof++NevTc8bDh6vFOtHZqXqtUtX12abSyeiVIyqzjcz/vr+4TshZmNd/VwpooAz4AYUY6lkBlmVzf6GRTRHrsxeOZ/LiOvVfO2tpW6b7W+SNc46zZKgw120kJB6lsj2uPYFFzcj+fbXUyynk/14MUPWDtuOf2a6ewSbkgsVM6dYSSZjkuXWZJlr+Ve4m4zN9/HBfOR+02oNrCrcBT60FlD+jlW7ifK6n9qf1es57XcDNgK2WqOkYnnyKcK+8Kqo/R471Htw1R/xRb1aej5O7RujADmMmoQek/lXoYM+1ft0VB+vFJrVfzMo2jiEewfhT7Pdv0oYfo85Kh1hvxPVJaTzj2VpC+JFuc5GrLrW+2t7A1Zf32Fsoqp6P/xr5+muPYRYLUshzPxH4G/3gnmcF+VgvxL3VrkID/C4IECCBIgACCBAggSIAAggQIIEiAAIIECCBIgIBGkKxRAZ/6A5ca7yPp8Ktz66iJEnDlamlnDTkCLp0EyRoWdkAfZiRAwOVTO5IEXLt62GCN0ifv7AFwruPxN9MRcI0PZAEBBAkQQJAAAQQJEECQAAEECRBAkAABBAkQQJAAAQQJEECQAAG8ag4I4FVzQAAv9gECeNUcEMCMBAjgVXNAAK+aAwJ41RwQwAeygACCBAggSIAAggQIIEiAAIIECCBIgACCBAggSIAAggQIIEiAgLMgWcMv2gFdzn9plSABXc7fkCVIQBeCBAggSIAAggQIIEiAAP6nVUAAH8gCAggSIIAgAQIIEiCAIAECCBIggCABAggSIIAgAQIIEiCAIAECCBIggCABAggSIIAgAQIIEiCAIAECCBIggCABAn4BBRX8efcOY00AAAAASUVORK5CYII=" alt="" />

  


其他数学类型相关模块:

  decimal           十进制浮点运算类  Decimal

  array              高效数值数组(字符,整数,浮点数等等)

  math/cmath    标准C库数学运算函数。常规数学运算在match模块, 复数运算在cmath模块
  operator         数字运算符的函数实现 。比如 operator.sub(m,n) 等价于 m-n 。

  ……

  感兴趣的自行了解

python内建函数-数字相关的更多相关文章

  1. python 内建函数setattr() getattr()

    python 内建函数setattr() getattr() setattr(object,name,value): 作用:设置object的名称为name(type:string)的属性的属性值为v ...

  2. python 内建函数 filter,map和reduce

    python 内建函数 filter,map和reduce, 三个函数比较类似,都是应用于序列的内置函数,常见的序列包括list.tuple.str等.而且三个函数都可以和lambda表达式结合使用. ...

  3. Python内建函数-callable

    Python内建函数-callable callable(object) 中文说明:检查对象object是否可调用.如果返回True,object仍然可能调用失败:但如果返回False,调用对象ojb ...

  4. Python内建函数enumerate()用法及在for循环应用

    Python 内建函数enumerate() 由于这个单纯很长,不容易记住,用法还是比较广泛的,下面讲述Python内建函数enumerate()用法. 1,实例 enumerate(sequence ...

  5. Python内建函数reduce()用法

    reduce把一个函数作用在一个序列[x1, x2, x3...]上,这个函数必须接收两个参数,reduce把结果继续和序列的下一个元素做累积计算,下面讲述Python内建函数reduce()用法. ...

  6. python 内建函数 type() 和 isinstance() 介绍

    Python 不支持方法或函数重载, 因此你必须自己保证调用的就是你想要的函数或对象.一个名字里究竟保存的是什么?相当多,尤其是这是一个类型的名字时.确认接收到的类型对象的身份有很多时候都是很有用的. ...

  7. python内建函数sorted方法概述

    python中,具体到对list进行排序的方法有俩,一个是list自带的sort方法,这个是直接对list进行操作,只有list才包含的方法:另外一个是内建函数sorted方法,可以对所有可迭代的对象 ...

  8. python 内建函数 str() 和 repr() 的区别

    1.内建函数str()和repr() 或反引号操作符(``)可以方便地以字符串的方式获取对象的内容.类型.数值属性等信息. 2.str()函数得到的字符串可读性好(故被print调用) 3.repr( ...

  9. python 内建函数

    # # __geratteibute__class Itcast(object): def __init__(self,subject1): self.subject1 = subject1 self ...

随机推荐

  1. 翻译:Knockout 轻松上手 - 1 Knockout 是什么?

    原文名称:KnockoutJS Starter Knockout 是一个非常棒的脚本库,可是我发现许多人并不了解它,所以,思胜翻译了这本著作. 这一节,我们将会讨论 Knockout 可以做什么,又如 ...

  2. Android WebView Long Press长按保存图片到手机

    <span style="font-size:18px;">首先要先注册长按监听菜单 private String imgurl = ""; /** ...

  3. 如何让 Drupal 使用 Wordpress 形式的编辑代码?

    如果你曾有过将 Wordpress 网站迁移到 Drupal 的经验,很可能客户会问的第一件事就是如何为 Drupal 添加编辑代码. Wordpress 中的 Shortcodes 插件让使用者可以 ...

  4. powerdesigner中怎么给一主键设为自增型auto increme

    在使用powerdesigner 设计数据库表时,通常要对主键进行设置,如果主键是int 类型,一般会设置成自增,那么怎么在 powerdesigner 中设置呢,以下是具体的方法: 在所要设为自增型 ...

  5. [linux]查看文件编码和编码转换

    方法一:file filename 方法二:在Vim中可以直接查看文件编码 :set fileencoding 即可显示文件编码格式. 如果你只是想查看其它编码格式的文件或者想解决用Vim查看文件乱码 ...

  6. php 5.6.14手动安装 php -v 显示没有安装

    奇怪了,今天利用源码手动php,安装成功后,利用php -v提示没有安装,which php也是有问题,php文件也没有办法执行 搞了半天,发现是没有添加环境变量,╮(╯▽╰)╭ 方法: 修改/etc ...

  7. 学习总结 Java 基本数据类型 和标识符以及常用的关键字

    思维导图: public static void main(String[] args) { // java程序的入口点 c#是Main System.out.println("测试输出&q ...

  8. 洛谷P2722 总分 Score Inflation

    P2722 总分 Score Inflation 184通过 295提交 题目提供者该用户不存在 标签USACO 难度普及- 提交  讨论  题解 最新讨论 关于算法 题目背景 学生在我们USACO的 ...

  9. Vim与GCC和gdb完美组合

    一.vim vim修改一下配置文件后,如果你稍微会点vim的命令使用,那可比一般的编辑器好用啊,如果一点不会vim的命令使用,就跟一般编辑器一样使用. 打开etc/vim/vimrc文件 这里的引号是 ...

  10. Duilib学习笔记《04》— 窗体显示

    在前面已经了解了duilib控件以及界面布局相关内容,接下来就要考虑该如何将xml中描述的布局通过界面展现出来.实际上在 Duilib学习笔记<01> 中我们已经简单提到过基本的流程及元素 ...