Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Articles - Page 911 of 1048
466 Views
There are a variety of mathematical series which python can handle gracefully. One such series is a series of repeated digits. Here we take a digit and add it to the next number which has two such digits and again the next number is three such digits and so on. Finally, we calculate the sum of all such numbers in the series.ApproachWe take a digit and convert it to string. Then concatenate two such strings to get the double digit number and keep concatenating to get higher numbers of such digits. Then we implement a recursive function to add all ... Read More
2K+ Views
Here we will see the bisect in Python. The bisect is used for binary search. The binary search technique is used to find elements in sorted list. The bisect is one library function.We will see three different task using bisect in Python.Finding first occurrence of an elementThe bisect.bisect_left(a, x, lo = 0, hi = len(a)) this function is used to return the left most insertion point of x in a sorted list. Last two parameters are optional in this case. These two are used to search in sublist.Examplefrom bisect import bisect_left def BinSearch(a, x): i = bisect_left(a, x) ... Read More
6K+ Views
With the increase in popularity of the Python programming language, more and more features are becoming available for Python developers. Usage of these features helps us to write efficient code. In this article, we will see 10 Python tricks that are very frequently used. Reversing a List We can reverse a given list by using the reverse() function. It returns the elements of the current list in reverse order. It works with both numeric and string datatypes. Example Let's see how to use the reverse() function in your Python program to reverse a list of strings: List = ["Shriya", "Lavina", "Sampreeti" ... Read More
311 Views
Create a Python ListExampleC:\Py3Project>howdoi create a python listOutputRunning the above code gives us the following result −>>> l = [None] * 10 >>> l [None, None, None, None, None, None, None, None, None, None]Printing Today’s DateExamplec:\python3>howdoi print today's date in pythonOutputRunning the above code gives us the following result −for date in mylist : print str(date)Examplec:\python3>howdoi create fibonnaci series in pythonOutputRunning the above code gives us the following result −def F(n): if n == 0: return 0 elif n == 1: return 1 else: return F(n-1)+F(n-2)Examplec:\python3>howdoi use calendar in javascriptOutputRunning the above code gives us the following ... Read More
1K+ Views
In python the print statement adds a new line character by default. So when we have multiple print statements the output from each of them is printed in multiple lines as you can see in the example below. Our goal is to print them in a single line and use some special parameters to the print function to achieve that.Normal Print()The below example prints multiple statements with new lines in each of them.Exampleprint("Apple") print("Mango") print("Banana")OutputRunning the above code gives us the following result −Apple Mango BananaUsing end ParameterWe can use the end parameter to use a specific character at the ... Read More
1K+ Views
Google offers many python packages which minimize the effort to write python code to get data from google services. One such package is google images download. It takes in the key words as parameters and locates the images with those keywords.ExampleIn the below example we limit the number of images to 5 and also allow the program to print the urls from where the files were generated.from google_images_download import google_images_download #instantiate the class response = google_images_download.googleimagesdownload() arguments = {"keywords":"lilly, hills", "limit":5, "print_urls":True} paths = response.download(arguments) #print complete paths to the downloaded images print(paths)OutputRunning the above code gives us the following ... Read More
6K+ Views
In Python sometimes we have link the output and we want to clear the screen in the cell prompt we can clear the screen by pressing Control + l . But there are situations when we need to clear the screen programmatically depending on the amount of output from the program and how we want to format the output. In such case we need to put some commands in the python script which will clear the screen as and when needed by the program.We need the system() from the OS module of python to clear up the screen. For different ... Read More
174K+ Views
There is a need to generate random numbers when studying a model or behavior of a program for different range of values. Python can generate such random numbers by using the random module. In the below examples we will first see how to generate a single random number and then extend it to generate a list of random numbers.Generating a Single Random NumberThe random() method in random module generates a float number between 0 and 1.Exampleimport random n = random.random() print(n)OutputRunning the above code gives us the following result −0.2112200Generating Number in a RangeThe randint() method generates a integer between ... Read More
2K+ Views
Greatest common divisor or gcd is a mathematical expression to find the highest number which can divide both the numbers whose gcd has to be found with the resulting remainder as zero. It has many mathematical applications. Python has a inbuilt gcd function in the math module which can be used for this purpose.gcd()It accepts two integers as parameter and returns the integer which is the gcd value.SyntaxSyntax: gcd(x, y) Where x and y are positive integers.Example of gcd()In the below example we print the result of gcd of a pair of integers.import math print ("GCD of 75 and 30 ... Read More
380 Views
This function helps in converting a mutable list to an immutable one. This is needed when we have declared a list whose items are changeable but after certain steps we want to stop allowing the elements in it to change. In such scenario, we apply the frozenset() function as shown below.SyntaxSyntax: frozenset(iterable_object_name)In the below example we take a list, change its element and print it. Then in the next step we apply the frozenset function, and try changing the element again. In the second step we get the error showing that the list can not be modified anymore.Example# Before applying ... Read More