Ad
Why Does A Variable Given Data Type "range" Still Show As "list" When The "type" Function Is Used On It?
While studying data types in Python, I encountered a data type range and used a variable to define it. However using type function to know about this still tells that it's a list data types.
Am I missing something here? Please guide. Thank you so much.
x = range(3)
print(type(x))
Output is as shown below:
C:\Python27>python.exe learn.py
<type 'list'>
Ad
Answer
It seems you are mixing up Python 3 and 2. These are two major versions of Python. Python 3000 introduced many intentionally backwards incompatible changes including in the workings of the range function.
In Python 2, the range function immediately expanded out to a list
list_range = list(range(3))
In Python 3 it is just a mapping to the range data type.
Check the official docs here [https://docs.python.org/3.0/whatsnew/3.0.html]
It is something to do with memory.
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad