Found 10783 Articles for Python

What is PEP8?

Vikram Chiluka
Updated on 15-Sep-2022 09:33:17

2K+ Views

In this article, we will explain PEP8 and its uses in python. Also, we will see its advantages while coding. What is PEP8? PEP is an abbreviation for Python Enterprise Proposal. Writing code with good logic is a crucial aspect of programming, but many other important elements can affect the quality of the code. The developer's coding style makes the code more reliable, and every developer should remember that Python rigidly follows the string's order and format. A good coding style makes the code more readable. The code is simplified for the end user PEP 8 is a document that ... Read More

What is a default value in Python?

Vikram Chiluka
Updated on 15-Sep-2022 09:31:51

15K+ Views

The Python language has a different way of representing syntax and default values for function arguments. Default values indicate that if no argument value is given during the function call, the function argument will take that value. The default value is assigned by using the assignment (=) operator of the form keywordname=value. Example # creating a function by giving default values def tutorialspoint(website, author ='XYZ', language ='Python'): print(website, "website article is written by the author", author, "of language", language) Function call without keyword arguments Example # creating a function by giving default values def tutorialspoint(website, author ... Read More

Name mutable and immutable objects in Python

Vikram Chiluka
Updated on 15-Sep-2022 09:25:17

507 Views

In this article, we will explain to you the mutable and immutable objects in python. Python considers everything to be an object. A unique id is assigned to it when we instantiate an object. We cannot modify the type of object, but we may change its value. For example, if we set variable a to be a list, we can't change it to a tuple/dictionary, but we may modify the entries in that list. In Python, there are two kinds of objects. On the one hand, there are objects that can change their internal state (the data/content inside ... Read More

How do map, reduce and filter functions work in Python?

Vikram Chiluka
Updated on 15-Sep-2022 09:21:53

11K+ Views

In this article, we will show you the Python's map(), filter(), and reduce() functions add a touch of functional programming to the language. All three of these are convenience functions that can be replaced with List Comprehensions or loops but offer a more elegant and concise solution to some problems. map(), filter(), and reduce() all work in the same way. These functions accept a function and a sequence of elements and return the result of applying the received function to each element in the sequence. map() function Like reduce(), the map() function allows you to iterate over each item in ... Read More

Difference between indexing and slicing in Python

Vikram Chiluka
Updated on 15-Sep-2022 09:05:41

10K+ Views

In this article, we will explain to you the differences between indexing and slicing in python. Indexing and slicing are applicable only to sequence data types. The order in which elements are inserted is preserved in sequence type, allowing us to access its elements via indexing and slicing. To summarise, Python's sequence types are list, tuple, string, range, byte, and byte arrays. And indexing and slicing are applicable to all of these types. Indexing The term "indexing" refers to refers to an element of an iterable based on its position inside the iterable. The indexing begins from 0. The ... Read More

Difference between for loop and while loop in Python

Vikram Chiluka
Updated on 26-Aug-2023 03:25:00

44K+ Views

In this post, we will understand the difference between the 'for' and the 'while' loop. For Loop A for loop is a control flow statement that executes code for a predefined number of iterations. The keyword used in this control flow statement is "for". When the number of iterations is already known, the for loop is used. The for loop is divided into two parts − Header − This part specifies the iteration of the loop. In the header part, the loop variable is also declared, which tells the body which iteration is being executed. Body − The body part ... Read More

Built-in functions supported by dictionary view objects

Govind
Updated on 25-Aug-2022 11:38:58

384 Views

The dictionary view objects include dict.keys(), dict.values(), dict.items(). They are used to obtain the dynamic view of the dictionary elements in python. These objects reflect the changes made to the dictionary. To retrieve some data or perform various operations on these view objects, there are 5 build-in functions in python that are supported. They are as follows − len(obj) iter(obj) reversed(obj) sorted(obj) ist(obj) We will discuss about all the functions mentioned above in this article. The len(obj) method The len(obj) method takes a view object as a parameter and returns the number of items in the dictionary. Example ... Read More

Python Program to Read First n Lines of a File

Vikram Chiluka
Updated on 18-Aug-2022 09:01:10

15K+ Views

In this article, we will show you how to read and print the first N lines of a text file for the given N value using python. Assume we have taken a text file with the name ExampleTextFile.txt consisting of some random text. We will return the first N lines of a text file for the given N value. ExampleTextFile.txt Good Morning Tutorials Point This is Tutorials Point sample File Consisting of Specific abbreviated source codes in Python Seaborn Scala Imagination Summary and Explanation Welcome user Learn with a joy Algorithm (Steps) Following are the Algorithm/steps to be followed ... Read More

How to Print Lines Containing Given String in File using Python?

Vikram Chiluka
Updated on 18-Aug-2022 08:56:52

6K+ Views

In this article, we will show you how to print all the lines that contain a given specific string in a given text file using python. Assume we have taken a text file with the name ExampleTextFile.txt consisting of some random text. We will return the lines from a text file containing a given particular string from a text file. ExampleTextFile.txt Good morning to TutorialsPoint This is TutorialsPoint sample File Consisting of Specific source codes in Python, Seaborn, Scala Summary and Explanation Welcome to TutorialsPoint Learn with a joy Good morning to TutorialsPoint Algorithm (Steps) Following are the Algorithm/steps ... Read More

How to Find the Most Repeated Word in a Text File using Python?

Vikram Chiluka
Updated on 18-Aug-2022 08:50:24

9K+ Views

In this article, we will show you how to find the most repeated word in a given text file using python. Assume we have taken a text file with the name ExampleTextFile.txt consisting of some random text. We will return the most repeated word in a given text file ExampleTextFile.txt Good Morning TutorialsPoint This is TutorialsPoint sample File Consisting of Specific source codes in Python, Seaborn, Scala Summary and Explanation Welcome TutorialsPoint Learn with a joy Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task − Import the Counter function (The Counter class ... Read More

Advertisements