Category: python basic

python tutorials and learn python

Created with Sketch.

Python – Iterator

Python – Iterator Here, you will learn about the iterator function iter() in Python. Iterators are implicitly used whenever we deal with collections of data types such as list, tuple or string (they are quite fittingly called iterables). The usual method to traverse a collection is using the for loop, as shown below. Example: myList…
Read more

Python – Creating and Installing a Package

Python – Creating and Installing a Package We organize a large number of files in different folders and subfolders based on some criteria, so that we can find and manage them easily. In the same way, a package in Python takes the concept of the modular approach to next logical level. As you know, a…
Read more

Python – Random Module

Python – Random Module Functions in the random module depend on a pseudo-random number generator function random(), which generates a random float number between 0.0 and 1.0. random.random(): Generates a random float number between 0.0 to 1.0. The function doesn’t need any arguments. >>>import random >>>random.random() 0.645173684807533 random.randint(): Returns a random integer between the specified…
Read more

Python – Collections Module

Python – Collections Module The collections module provides alternatives to built-in container data types such as list, tuple and dict. namedtuple() The namedtuple() function returns a tuple-like object with named fields. These field attributes are accessible by lookup as well as by index. General usage of this function is: Signature: collections.namedtuple(type_name, field-list)   The following…
Read more

Python – Statistics Module

Python – Statistics Module The statistics module provides functions to mathematical statistics of numeric data. The following popular statistical functions are defined in this module. The mean() method calculates the arithmetic mean of the numbers in a list. >>> import statistics >>>statistics.mean([2,5,6,9]) 5.5 The median() method returns the middle value of numeric data in a…
Read more

Python – Math Module

Python – Math Module Some of the most popular mathematical functions are defined in the math module. These include trigonometric functions, representation functions, logarithmic functions, angle conversion functions, etc. In addition, two mathematical constants are also defined in this module. Pie (π) is a well-known mathematical constant, which is defined as the ratio of the…
Read more

Python – Sys Module

Python – Sys Module The sys module provides functions and variables used to manipulate different parts of the Python runtime environment. You will learn some of the important features of this module here. sys.argv sys.argv returns a list of command line arguments passed to a Python script. The item at index 0 in this list…
Read more

Python – OS Module

Python – OS Module It is possible to automatically perform many operating system tasks. The OS module in Python provides functions for creating and removing a directory (folder), fetching its contents, changing and identifying the current directory, etc. Creating Directory We can create a new directory using the mkdir() function from the OS module. >>>…
Read more

Python-Built-in Modules in Python

Built-in Modules in Python The Python interpreter has a number of built-in functions. They are loaded automatically as the interpreter starts and are always available. Many of them have been discussed in previous tutorials. For example, print() and input() for I/O, number conversion functions int(), float(), complex(), data type conversions list(), tuple(), set(), etc. In…
Read more

Python – Module Attributes

Python – Module Attributes A module is described by its attributes. The attributes of a module perform some tasks or contain some information. Some of the important attributes are explained below: __name__ Attribute The __name__ attribute returns the name of the module. By default, the name of the file (excluding the extension .py) is the…
Read more