发布新日志

  • python字典与列表的使用--记录

    2019-01-22 17:41:18

    import requests
    import random
    import time
    import datetime
    def send_post(url, data):
        res = requests.post(url=url, data=data)
        return res.text
    tp = [
        {'userBindPhone': '18980001005', 'userId': '17081687'},
        {'userBindPhone': '13100020000', 'userId': '17087391'},
        {'userBindPhone': '13810086000', 'userId': '17084908'}
          ]
    extend = {'ifBuyTttb': '0',
                'productcode': '0118003',
                'sign': '493SSB6FE7A669A43A97896AB90',
                'timestamp': '20190122105341',
                'uid': 'A30FC9C41C77777777E06F864A2937'
               }
    url = 'http://xxx.xxx/useraction/getInDCCB'
    for tpdata in tp:
        tpdata.update(extend)
        tpdata['money'] = (random.randint(1, 9)) * 100 # 生成1到9之间的随机数,再乘以100就是的购买金额
        print(send_post(url, tpdata), datetime.datetime.now())

  • 学习这几个函数pow、abs、round、floor、sqrt

    2012-05-29 11:14:50

    前几天因为要参加考试,暂停学习python,现在考完了。又可以继续啦。
    今天主要学习这几个函数pow、abs、round、floor、sqrt。
    pow():指数运算。
           两个参数时类似于**;
           pow()还接受第三个可选的参数,一个余数参数。如果有这个参数的, pow() 先进行指数运算,然后将运算结果和第三个参数进行取余运算。
    例:pow(2,3)  结果为:8
        pow(4,3,5) 结果为:4 
     pow(4,3,5)相当于pow(4,3)%5  结果为4
    abs():求绝对值;
    例:abs(-1), abs(1)结果为1
    round():对浮点数进行四舍五入运算。
    round(25.225,2) 结果:25.23
     
    floor和sqrt函数需要用import来导入如:
    import math
    math.floor(23.9)

    from math import floor
    floor(23.9)
    结果都为:23.0
    import math
    math.sqrt(9)
    结果为:3
  • 日志 [2012年05月21日] python学习

    2012-05-21 16:50:20

    很久都没有认真学习一下,今天终于静下来学习python,算是为测试Android的应用做些准备吧。
    第一天:Hello World
    python 3.X 需要用:print("Hello, World")
    ptyhon 2.7  用 print "Hello, World"
     
     
    python 注释一行用: #
    注释多行用:
    '''
     被注释的内容
     被注释的内容
    '''
     
    注释在程序运行时是不会显示的,需要显示用print语句。  
Open Toolbar