推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
CivAx
V2EX  ›  Python

有 Python 大佬帮忙看看这个 [0] 是什么用法吗

  •  
  •   CivAx · Oct 23, 2019 · 3066 views
    This topic created in 2426 days ago, the information mentioned may be changed or developed.

    代码:

    fresponse = json.loads(response)
    url = fresponse["Items"]["Backup"][0]["BackupIntranetDownloadURL"]
    print (url)
    

    这个 Response 是一串 JSON 返回值:

    {
       "Items": {
    	  "Backup": [
    		{
    			"StoreStatus": "Disabled",
    			"HostInstanceID": 87611,
    			"BackupLocation": "OSS",
    			"BackupIntranetDownloadURL": "http://downloadURL/",
    			"BackupType": "FullBackup",
    			"InstanceId": "a40518nc69"
             }
           ]
         }
       "TotalBackupSize": "1260323400",
       "PageNumber": 1,
       "TotalRecordCount": 1
    }
    

    不加 [0] 的时候直接请求,会连续不换行地 print 两次结果;加 [0] 与加 [1] 是一个结果;

    而且当没有 ["BackupIntranetDownloadURL"] 的时候,[0] 可以写为 print (url[0])

    请问这个 [0] 是哪个函数的什么用法?变换了几个关键字检索了谷歌,也都没有什么答案。

    joyme
        1
    joyme  
       Oct 23, 2019
    这不就是个数组吗、、
    hellwys1
        2
    hellwys1  
       Oct 23, 2019   ❤️ 1
    你这谷歌有点水啊……
    菜鸟教程有请。
    https://www.runoob.com/python3/python3-list.html
    msg7086
        3
    msg7086  
       Oct 23, 2019
    请学习一下数组的使用方法。
    flyingghost
        5
    flyingghost  
       Oct 23, 2019
    "Backup": [
    硕大一个 [ 号已经说明这是一个数组了。
    kevinmissu
        6
    kevinmissu  
       Oct 23, 2019
    不懂就问是好事,问之前建议百度一下!!!!
    rooob1
        7
    rooob1  
       Oct 23, 2019
    基础中的基础知识 数组 []
    helone
        8
    helone  
       Oct 23, 2019
    数组,下标是 0。。。
    brave256
        9
    brave256  
       Oct 23, 2019   ❤️ 1
    不加[0]后面直接["BackupIntranetDownloadURL"]会报异常的,[0]是取出列表中的第一个元素就是“Backup”里的那个字典,然后才能使用["BackupIntranetDownloadURL"]取出这个键的值
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2873 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 73ms · UTC 12:16 · PVG 20:16 · LAX 05:16 · JFK 08:16
    ♥ Do have faith in what you're doing.