Python

Python JSON Example

When you define a python dict variable like below, the variable’s value is saved in memory when the program runs: d = dict(name=’Richard’, age=25, score=100) You can change the variable value at any time, such as changing the name to ‘Tom’, but once the program ends, the memory taken by the variable is completely reclaimed …

Python JSON Example Read More »

Python3 urllib.request.urlopen Example

The urllib.request.urlopen() function is used to implement access to the target url. This function will return an object which can be used to get the url webpage status and content data. The function prototype is as follows. urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capath=None, cadefault=False, context=None) 1. urlopen Method Arguments. Below is the function parameter description. …

Python3 urllib.request.urlopen Example Read More »

Python Immutable Objects

For mutable objects, such as a list, to operate on a list, the contents within the list will change, for example. >>> l = [‘f’, ‘e’, ‘d’] >>> l.sort() >>> ; [‘d’, ‘e’, ‘f’] What about immutable objects, like string. >>> str = ‘hello’ >>> str.replace(‘h’, ‘F’) ‘Fello’ >>> str ‘hello’ Even though the string …

Python Immutable Objects Read More »