
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
Found 10476 Articles for Python

2K+ Views
Python is one of the preferred languages among coders for most of the competitive programming challenges. Most of the problems are easily computed in a reasonable time frame using python.For some of the complex problem, writing fast-enough python code is often a challenge. Below are some of the pythonic code constructs that help to improve the performance of your code in competitive coding −1. Strings concatenation: Do not use the below construct.str1 = "" some_list = ["Welcome ", "To ", "Tutorialspoint "] for x in some_list: str1 += x print(str1)Above method gives huge time overhead.Instead, try to use this ... Read More

259 Views
Competitive programming is generally referred to coding to make use of efficient algorithms using an appropriate data structure. They test the skills of programmers on many levels.With the help of algorithms and data structures, you have to solve a hypothetical programming problem posed to you by applying different logics. You not only have to solve the problem but you have to come up with a very efficient solution, which is having a good time and space complexity.Example of a problem statement for what is called competitive programming might be −You are given a string s of length n consisting only ... Read More

687 Views
Serialization is a process in which an object is transformed into a format that can be stored/save (in a file or memory buffer), so we are able to deserialize it later and recover the original content/object from the serialized format. We are going to use a python pickle module to do all these operations.What is pickling?Python pickle module is used for serializing and de-serializing python object structures. The process to converts any kind of python objects (list, dict, etc.) into byte streams (0s and 1s) is called pickling or serialization or flattening or marshaling. We can convert the byte stream ... Read More

1K+ Views
In this article, we will try to do google search using python code, this comes handy in case you are working on a python project and you need to access some data from the web and the search result(from the web) is going to be used inside your project.Prerequisite –You must have python installed on your system.Install google module. You can use pip to install google module like below −C:\Users\rajesh>python -m pip install google Collecting google Downloading https://files.pythonhosted.org/packages/c8/b1/887e715b39ea7d413a06565713c5ea0e3132156bd6fc2d8b165cee3e559c/google-2.0.1.tar.gz Requirement already satisfied: beautifulsoup4 in c:\python\python361\lib\site-packages (from google) (4.6.0) Installing collected packages: google Running setup.py install for google ... done Successfully installed ... Read More

1K+ Views
All python program automatically compiles your source code to compile code also called as byte code, before executing it.Whenever we import a module for the first time or when your source file is a new file or we have an updated file then the recently compiled file, a .pyc file will be created on compiling the file in the same directory as the .py file (from python 3- you might see .pyc file is in a subdirectory called __pycache__ instead in the same directory as your .py file). This is a time-saver mechanism as it prevents python to skip the ... Read More

215K+ Views
A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. Any whole number which is greater than 1 and has only two factors that is 1 and the number itself, is called a prime number Let’s say the following is our input − 7 The output should be as follows − Prime Number Check if a number is Prime or not Let us check if a number if a Prime number or not using the for loop − Example # Number to be checked for prime n ... Read More

783 Views
To use exception handling in python, we first need to catch the all except clauses.Python provides, “try” and “except” keywords to catch exceptions. The “try” block code will be executed statement by statement. However, if an exception occurs, the remaining “try” code will not be executed and the except clause will be executed.try: some_statements_here except: exception_handlingLet’s see above syntax with a very simple example − Live Demotry: print("Hello, World!") except: print("This is an error message!")OutputHello, World!Above is a very simple example, let’s understand the above concept with another example − Live Demoimport sys List = ['abc', 0, 2, ... Read More

1K+ Views
There are numerous situation occurs when we want our program to do this specific task, irrespective of whether it runs perfectly or thrown some error. Mostly to catch at any errors or exceptions, we use to try and except block.The “try” statement provides very useful optional clause which is meant for defining ‘clean-up actions’ that must be executed under any circumstances. For example −>>> try: raise SyntaxError finally: print("Learning Python!") Learning Python! Traceback (most recent call last): File "", line 2, in raise SyntaxError File "", line None SyntaxError: The final clause ... Read More

228 Views
Here we are trying to do two tasks at a time, one in the foreground and the other in the background. We’ll write something in the file in the background and of a user input number, will find if it’s an odd or even number.Doing multiple tasks in one program in python is possible through multithreading in Live Demoimport threading import time class AsyncWrite(threading.Thread): def __init__(self, text, out): threading.Thread.__init__(self) self.text = text self.out = out def run(self): f = open(self.out, "a") f.write(self.text + '') ... Read More

33K+ Views
FunctionA function is a block of code to carry out a specific task, will contain its own scope and is called by name. All functions may contain zero(no) arguments or more than one arguments. On exit, a function can or can not return one or more values.Basic function syntaxdef functionName( arg1, arg2, ...): ... # Function_body ...Let's create our own (user), a very simple function called sum (user can give any name he wants). Function "sum" is having two arguments called num1 and num2 and will return the sum of the arguments passed to the function(sum). When ... Read More