Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint
Cover Image
Cover Image
Drag to reposition
Contributed Answers

How do we assign a value to several variables simultaneously in Python?

How do we assign a value to several variables simultaneously in Python instead of using separate assignment for each variable?
Answered on 2nd Jan, 2018, 0 Views

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 .....

How does Python generate random numbers?

How does Python generate random numbers? Which are the different functions available for the purpose in Python?Give some suitable examples.
Answered on 2nd Jan, 2018, 0 Views

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 ,

How do make a flat list out of list of lists in Python?

How do make a flat list out of list of lists in Python? Give an example of flattening of lists in Python?
Answered on 2nd Jan, 2018, 0 Views

If you have a list object where each item is a list itself, and you put all items of all lists in another list object, it is called flat list. For example,

How to check if a list is empty in Python?

Can we create an empty list object in Python? How to check if a list is empty in Python? Explain with example
Answered on 2nd Jan, 2018, 0 Views

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 ,

How can we use complex numbers in Python?

What is a complex number? How can we use complex numbers in Python? How can we convert integer to complex number?
Answered on 2nd Jan, 2018, 0 Views

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 .....

How do we create python string from list?

How do we create python string from list? Is there any function to convert a string to list object in Python?
Answered on 2nd Jan, 2018, 0 Views

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 ,

How would you make a comma-separated string from a list in Python?

A string with words separated by comma is to be converted to a Python list object. How would you make a comma-separated string from a list in Python?
Answered on 2nd Jan, 2018, 0 Views

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 ‘,’. ,

How can we convert a list of characters into a string in Python?

I have to form a string of all items in a list object. How can we convert a list of characters into a string in Python?
Answered on 2nd Jan, 2018, 0 Views

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 ,

How to get first 100 characters of the string in Python?

Assume that there is along sequence of characters in a string object. How to get first 100 characters of the string in Python?
Answered on 1st Jan, 2018, 0 Views

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.....

How to randomly select an item from a list in Python?

How to randomly select an item from a list in Python? Can we use random module functios for the purpose?
Answered on 1st Jan, 2018, 0 Views

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 .....

loader
Advertisements
Contribution

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.