Found 10476 Articles for Python

Difference between for loop and while loop in Python

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

52K+ 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

511 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

19K+ 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

7K+ 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

How to Find the Longest Words in a Text File using Python?

Vikram Chiluka
Updated on 18-Aug-2022 08:43:57

14K+ Views

In this article, we will show you how to print all the longest words from a given text file using python. The longest words are the words which are having the same length as the longest word (maximum length) in a text file. Assume we have taken a text file with the name ExampleTextFile.txt consisting of some random text. We will return all the longest words from a given text file. 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 ... Read More

How to Split given list and insert in excel file using Python?

Vikram Chiluka
Updated on 18-Aug-2022 08:42:14

4K+ Views

In this article, we will show you how to split the list and insert those into an excel file using python. Assume we have taken a static list and split that list and insert those list items into an excel file, by returning an excel file say outputExcelFile.xlsx containing the below output. outputExcelFile.xlsx Player Name Country Virat Kohli India Bhuvaneshwar Kumar India Mahendra Singh Dhoni India Rashid Khan Afghanistan Hardik Pandya India David Warner Australia West Indies Kieron Pollard India Rohit Sharma ... Read More

How to get values of all rows in a particular column in openpyxl in Python?

Vikram Chiluka
Updated on 18-Aug-2022 08:37:39

9K+ Views

In this article, we will show you how to get all the row values of a particular column in an excel file using the python openpyxl library. Assume we have taken an excel file with the name sampleTutorialsPoint.xlsx containing some random data. We will return all the row values of a given particular column in an excel file. sampleTutorialsPoint.xlsx Player Name Age Type Country Team Runs Wickets Virat Kohli 33 Batsman India Royal Challengers Bangalore 6300 20 Bhuvaneshwar Kumar 34 Batsman India Sun Risers Hyderabad 333 140 Mahendra Singh Dhoni 39 Batsman ... Read More

How to get sheet names using openpyxl in Python?

Vikram Chiluka
Updated on 18-Aug-2022 08:39:44

16K+ Views

In this article, we will show you how to get all the sheet names found in an excel file using python openpyxl library. Assume we have taken an excel file with the name sampleTutorialsPoint.xlsx containing multiple sheets with some random data. We will return all the sheet names found in a given excel file using the sheetnames attribute. sampleTutorialsPoint.xlsx firstSheet Player Name Age Type Country Team Runs Wickets Virat Kohli 33 Batsman India Royal Challengers Bangalore 6300 20 Bhuvaneshwar Kumar 34 Batsman India Sun Risers Hyderabad 333 140 Mahendra Singh Dhoni 39 ... Read More

How to find the number of Blank and Non-Blank cells in the Excel table using Python?

Vikram Chiluka
Updated on 18-Aug-2022 08:32:17

2K+ Views

In this article, we will show you how to find the count of a number of blank and non-blank (filled) cells in an excel worksheet using python. Assume we have taken an excel file with the name demoTutorialsPoint.xlsx containing some random data with some blank cells. We will return the count of a number of blank and non-blank (filled) cells in an excel worksheet. sampleTutorialsPoint.xlsx Player Name Age Type Country Team Runs Wickets Virat Kohli Batsman India Royal Challengers Bangalore 20 34 Batsman India Sun Risers Hyderabad 333 140 ... Read More

Advertisements