- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 34490 Articles for Programming
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
610 Views
In the terminal, if you want to make some texts appears in colored mode, there are numerous ways in python programming to achieve it.Using python modules1.termcolor module: It is the ANSII Color formatting for output in the terminal.import sys from termcolor import colored, cprint text1 = colored('Hello, Tutorialspoint!', 'blue', attrs=['reverse', 'blink']) print(text1) cprint('Hello, Python!', 'blue', 'on_white') print_red_on_blue = lambda x: cprint(x, 'red', 'on_blue') print_red_on_blue('Hello, from Data Science!') print_red_on_blue('Hello, Python!') for i in range(10): cprint(i, 'green', end=' ') cprint("Attention!", 'blue', attrs=['bold'], file=sys.stderr)ResultRead More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
416 Views
Indexing of ndarrays can be done using the standard python x[obj] syntax, where x is the array and obj the selection.There are three kinds of indexing available −field accessbasic slicingadvanced indexingWhat kind of indexing will be there depends on obj. In this section, we are going to mainly concentrate on basic slicing & advanced indexing.We can divide advanced indexing into two parts −Integer array indexingBoolean indexingBasic SlicingPython basic concept of slicing is extended in basic slicing to n dimensions. As with python slice object which is constructed by giving a start, stop & step parameters to slice function. To get ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
218 Views
There are numerous ways to create a numpy array. Numpy provides two different kinds of ways to convert a ndarray to 1Darray: that is using the flatten() method and the other using the ravel() method.Example#Import required library, numpy import numpy as np #create an array from a list arr = np.array( [ (2, 7, 3, 4), (5, 6, 9, 1)]) #flatten_output print(arr.flatten()) #ravel_output print(arr.ravel())Output[2 7 3 4 5 6 9 1] [2 7 3 4 5 6 9 1]Now above we can see that both functions return the same list, so the question arises, why two methods for the same ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
724 Views
Sometimes there is a requirement to convert a string to a number (int/float) in data analysis. For each string, we can assign a unique integer value to differentiate string values.For this, we use the data in Comma Separated Values(CSV) files. Say we have an excel file containing CSV data as follow −CompanyIndustryRecommendationHDFC BankFinanceHoldApolloHealthcareBuyHeroAutomobileUnderperformYes BankFinanceHoldM&MAutomobileUnderperformFortisHealthcareBuyMarutiAutomobileUnderperformAbove is just a few lines from a large dataset, we need to give different recommendation .i.e. Buy, Hold, Underperform etc. integer values, which will link to our metadata. So for the above input, our expected output will be something like −CompanyIndustryRecommendationHDFC BankFinance2ApolloHealthcare1HeroAutomobile3Yes BankFinance2M&MAutomobile3FortisHealthcare1MarutiAutomobile3Here is a way ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
819 Views
Python memory management is straight forward. You don’t need to worry about memory management, as memory allocation and deallocation is automatic. one of the mechanisms of memory management is garbage collection. Let’s understand different aspects of garbage collection, Garbage collectionIt is the process by which shared computer memory is cleaned which is currently being put to use by a running program when that program no longer needs that memory. With garbage collection, that freed memory can be used by another program.There are two methods used by python for memory management −Reference countingGarbage collectionPython’s garbage collection is automatic but in some ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
6K+ Views
What is Regular Expression?In the real world, string parsing in most programming languages is handled by regular expression. Regular expression in a python programming language is a method used for matching text pattern.The “re” module which comes with every python installation provides regular expression support.In python, a regular expression search is typically written as:match = re.search(pattern, string)The re.search() method takes two arguments, a regular expression pattern and a string and searches for that pattern within the string. If the pattern is found within the string, search() returns a match object or None otherwise. So in a regular expression, given a ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
195 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
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
589 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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
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