In Python, variable is really a label or identifier given to object stored in memory. Hence, same object can be identified by more than one variables. , a, b and c are three variables all referring to same object. This can be verified by id() function. , Python also allows different values to be assigned to different variables in one statement. Values from a tuple object are unpacked to be .....
Standard distribution of Python has a random module that has functions for random number generation. Basic random() function returns a random floating point number between 0 and 1 , From same module, there is randrange() function which returns a random number between a sequential range. , There is also choice() function which randomly chooses an item from list or tuple ,
In Python, empty list object evaluates to false. Hence following conditional statement can be used to check if list is empty. , You can also use len() function. It returns number of elements in a sequence. If len() returns zero, the list is empty ,
A complex number is a pair of real numbers a and b, most often written as a+bi, or a+ib, where i is called the imaginary unit and acts as a label for the second term. Mathematically, i2 = -1. Sometimes, j is used instead of i. Here’s how a complex number is assigned to a variable: , Python has a built-in function complex() which returns a complex data type. complex(x) returns a .....
Python has an in-built join() function that returns a string by joining elements in a sequence object by inserting separator between elements. If we need a string without any separator, we initialize it with null string. For a comma separated string, initialize the variable to ‘,’. ,
The slice ( : ) operator in Python allows you to obtain a part of string. The slice operator has two operands, index of beginning of slice and end of slice. , In following example, three characters from 7th characters are obtained ( Python sequence uses zero based index) >>> var="Hello how are you?">>> str1=var[6:9]>>> str1'how' In order to obtain first 100 charac.....
Standard library of Python contains random module. This module has various pseudo random generators based on the Mersenne Twister algorithm. The module contains a choice() method that randomly chooses item from a sequence data type (string, list or tuple) , Another way is to have a random number corresponding to index of list items by using randrange() function. The range for random number .....
Sign up now to get your own personalized profile!
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more