Found 10784 Articles for Python

What makes Python Cool?

Pavitra
Updated on 29-Aug-2019 08:03:48

169 Views

In this article, we will learn about what all features makes python cool and different from other languages.>>>import thisOutputThe Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. The flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to ... Read More

Python vulnerability in input() function

Pavitra
Updated on 29-Aug-2019 07:55:48

404 Views

In this article, we will learn about how the input function behaves in an undesirable manner in version 2.x. Or earlier. In version 2.x. the raw_input() function works as replacement of the input() function . In newer versions 3.x. or later all the desirable features & functionalities of both functions are merged into the input() function.Firstly let’s look at the input type of built-in functions for taking input in Python 2.x.Example# Input Given : String str1 = raw_input("Output of raw_input() function: ") print type(str1) str2 = input("Output of input() function: ") print type(str2) # Input Given : Float str3 = ... Read More

Using Counter() in Python 3.x. to find minimum character removal to make two strings anagram

Pavitra
Updated on 29-Aug-2019 07:45:40

129 Views

In this article, we will learn about how we can make a string into a pangram using the counter() function in Python 3.x. Or earlier. To do so we are allowed to remove any character from the input string. We will also find the number of such required characters to be removed to make the string into an anagram.Two strings are said to be anagrams of each other when they contain the same type of alphabets in any random order.The counter () method is present in the collection module available in Python. The prerequisite is to import the collections module ... Read More

Use of min() and max() in Python

Pavitra
Updated on 29-Aug-2019 07:19:11

318 Views

In this article, we will be learning about min and max functions included in the Python Standard Library. It accepts infinite no of parameters according to the usageSyntaxmax( arg1, arg2, arg3, ...........)Return Value − Maximum of all the argumentsErrors & Exceptions: Here error is raised only in the scenario where the arguments are not of the same type. Error is encountered while comparing them.Let’s see what all ways we can implement the max() function first.Example Live Demo# Getting maximum element from a set of arguments passed print("Maximum value among the arguments passed is:"+str(max(2, 3, 4, 5, 7, 2, 1, 6))) # ... Read More

Union() function in Python

Pavitra
Updated on 29-Aug-2019 06:57:55

285 Views

In this article, we will be learning about union() i.e. one of the operations performed on the set() type. Union of all input sets is the smallest set which contains the elements from all sets excluding the duplicate elements present in sets.Syntax.union(, .......)Return type − typeSymbol − It is denoted by the first letter of function i.e. ‘U’ in probabilityExample Live Demo# Python 3.x. set union() function set_1 = {'a', 'b'} set_2 = {'b', 'c', 'd'} set_3 = {'b', 'c', 'd', 'e', 'f', 'g'}    # union operation on two sets print("set_1 U set_2 : ", set_1.union(set_2)) print("set_3 U set_2 ... Read More

Understanding Code Reuse and Modularity in Python 3

Pavitra
Updated on 29-Aug-2019 06:51:29

528 Views

Introduction to Object-Oriented Programming(OOP)?OOP refers to Object-Oriented Paradigm and is referred to as the heart of programming methodology. It includes several concepts like polymorphism, encapsulation, data hiding, data abstraction, inheritance & modularity.OOP gives data the prime consideration and by providing an interface through the functions associated with it. An object is a self-sufficient entity i.e. it has all the variables and associated functions with it. Objects have characteristics(variables) and features(methods), known as attributes.What is Modularity?Modularity refers to the act of partitioning the code into modules building them first followed by linking and finally combining them to form a complete project. ... Read More

Processing time with Pandas DataFrame

Pavitra
Updated on 29-Aug-2019 06:44:37

129 Views

In this article, we will learn about generating & processing different timestamps using built-in pandas library. We are also using the numpy module to generate and modify the database needed for the timestamp generation.Preferable IDE: Jupyter notebookBefore beginning this tutorial we must install pandas and numpy library. For this jupyter notebook is the best place to test and run your code. For installing pandas we must run the following command.>>> pip install pandasIf we run this command all the dependencies are automatically installed. After it’s done we must restart the kernel to see the changes.After we finished installing all the ... Read More

First-Class Citizens in Python

Pavitra
Updated on 29-Aug-2019 06:37:15

2K+ Views

First-class citizens are entities that enable support for all the operations facilitating other fellow entities.These entities are often used : while passing an argument , returning a value from function , conditional modifications & value assignment.In this article, we will look at the implementation & usage of first-class citizens in Python 3.x or earlier. Also, we will be learning what all entities get the tag of being First Class citizens.These citizens include Variables along with functions.Let’s first get familiar with the data types that are part of First-class citizensIntegersFloating typeComplex NumbersStringsAll four types mentioned above are given the tag of ... Read More

Learning Model Building in Scikit-learn: A Python Machine Learning Library

Pavitra
Updated on 29-Aug-2019 06:20:30

195 Views

In this article, we will learn about the Learning Model Building in Scikit-learn: A Python Machine Learning Library.It is a free machine learning library. It supports various algorithm like the random forest, vector machines & k-nearest neighbours with direct implementation with numpy and scipy.Importing the datasetimport pandas Url = < specify your URL here> data=pandas.rad_csv(url)Data exploration and cleaningWe can use the head method to specify/filter the records according to our needs.data.head() data.head(n=4) # restricting the record to be 4We can also implement the last few records of the datasetdata.tail() data.tail(n=4) # restricting the record to be 4Now comes the stage ... Read More

Keyboard module in Python

Pavitra
Updated on 28-Aug-2019 14:06:59

1K+ Views

In this article, we will learn about the use of the Keyboard module in Python 3.x. Or earlier.Ide preferred − Jupyter notebookInstallation −>>> pip install keyboardFunctionalities of the module −Allows us to block the action of specific keysWe can manage intents from the keyboard using on click listeners.Cross-platform compatibility.Supports special & hotkeys available on the keyboard.Now let’s implement this in the form of code −Exampleimport keyboard # It writes the content keyboard.write("Tutorialspoint") # It writes end of line keyboard.press_and_release('shift + o, shift + y, ') keyboard.press_and_release('k, j') # it blocks until ctrl keyboard.wait('Ctrl')OutputTutorialspoint O Y k jExampleimport keyboard # It ... Read More

Advertisements