LEARN PYTHON QUICKLY AND PYTHON CODING EXERCISES: Coding For Beginners by TAM JJ

LEARN PYTHON QUICKLY AND PYTHON CODING EXERCISES: Coding For Beginners by TAM JJ

Author:TAM, JJ [TAM, JJ]
Language: eng
Format: epub
Published: 2020-12-27T00:00:00+00:00


>>> temp . pop()

7

>>> temp . pop()

13

>>> temp . pop()

Traceback (most recent call last):

File "<stdin>" , line 1 , in <module>

KeyErro r : 'pop from an empty set'

Remove all elements from set

‘clear’ method is used to remove all elements from set.

>>> powersOf2

{16, 8, 2, 4, 1}

>>>

>>> powersOf2 . clear()

>>> powersOf2

set()

Python modules

Module is a file, which contains definitions. We can define classes, modules, variables etc., in module file and reuse them in other python scripts.

For example, create a file ‘arithmetic.py’ and copy following code.

arithmetic.py

def sum (a, b):

​ return a+ b

def subtract (a, b):

​ return a- b

def mul (a,b):

​ return a* b

def div (a, b):

​ return a/ b

Open python interpreter, import the module using ‘import’ key word and call the functions defined in module .

>>> impor t arithmetic

>>>



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.