zoukankan      html  css  js  c++  java
  • Python之基础(一)

    数学计算

    要利用相关的数学计算函数,首先需要把数学模块包含进来:

    >>>import math

    进行计算:

    >>> math.pi
    3.141592653589793
    >>> math.sqrt(90)
    9.486832980505138
    >>> 

    随机数

    包含随机函数:

    >>> random
    Traceback (most recent call last):
      File "<pyshell#27>", line 1, in <module>
        random
    NameError: name 'random' is not defined
    >>> import random
    >>> random.random()
    0.5821979178456164
    >>> random.choice([1, 3, 2, 4, 5])
    2

      Python also includes more exotic numeric objects—such as complex, fixed-precision, and rational numbers, as well as sets and Booleans—and the third-party open source extension domain has even more (e.g., matrixes and vectors, and extended precision numbers). We’ll defer discussion of these types until later in this chapter and book.

      So far, we’ve been using Python much like a simple calculator; to do better justice to its built-in types, let’s move on to explore strings.

    String

    >>> S = 'Spam'
    >>> len(S)
    4
    >>> S[0]
    'S'
    >>> S[-1]
    'm'
    >>> 

      注意:

      In Python, we can also index backward, from the end—positive indexes count from the left, and negative indexes count back from the right:

    >>> S[-1]
    'm'
    >>> S[-2]
    'a'
    >>> S[-3]
    'p'
    >>> S[-4]
    'S'
    >>> 
    >>> S *= 8
    >>> S
    'SpamSpamSpamSpamSpamSpamSpamSpam'
    >>> 

     File Operation:

  • 相关阅读:
    P1199三国游戏(博弈论)
    平方求和
    完全立方公式
    P1414 又是毕业季(数论)
    P1514 引水入城(搜索+线段完全覆盖)
    树莓派利用Django搭建聊天网页服务器 —— 准备篇
    树莓派下安装Django环境
    Linux终端光标消失问题
    OpenCV 简介
    树莓派是什么?能干什么?和单片机有什么区别?
  • 原文地址:https://www.cnblogs.com/wiessharling/p/3632453.html
Copyright © 2011-2022 走看看