Python Articles

Page 23 of 855

How to print double quotes with the string variable in Python?

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 14K+ Views

Printing double quotes with string variables can be tricky since double quotes are part of Python's string syntax. This article explores several methods to include double quotes in your printed output. Common Mistakes The following examples show what not to do when trying to print double quotes ? print(" ") print(" " " ") print(""aString"") The output of the above code is ? File "", line 3 print(""aString"") ^ SyntaxError: invalid syntax Method 1: ...

Read More

Bigram formation from given a Python list

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 880 Views

A bigram is a pair of consecutive words formed from a sentence. In Python, bigrams are heavily used in text analytics and natural language processing to analyze word patterns and relationships. What is a Bigram? A bigram takes every two consecutive words from a sentence and creates word pairs. For example, from "hello world python", we get bigrams: ("hello", "world") and ("world", "python"). Using enumerate() and split() This approach splits the sentence into words and uses enumerate() to create pairs from consecutive words ? sentences = ['Stop. look left right. go'] print("The given list ...

Read More

Avoiding quotes while printing strings in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 251 Views

When printing strings in Python, we often need to avoid displaying quotes around individual string elements. This is especially useful when working with lists of strings where we want clean, formatted output without the quotation marks that normally appear. Using join() Method The join() method combines list elements into a single string using a specified separator. This eliminates quotes around individual elements ? Example days = ['Mon', 'Tue', 'Wed'] # The given list print("The given list is : " + str(days)) print("The formatted output is : ") print(' ** '.join(days)) The output ...

Read More

askopenfile() function in Python Tkinter

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 2K+ Views

The askopenfile() function in Python Tkinter allows users to browse their file system and select a file through a graphical dialog box. This eliminates the need to hardcode file paths and provides a user-friendly way to open files in your applications. Syntax filedialog.askopenfile(mode='r', **options) Parameters The function accepts several optional parameters ? mode ? File opening mode (default is 'r' for read) initialdir ? Initial directory to open filetypes ? Specify allowed file types title ? Dialog window title Basic Example Here's a simple program that opens a file ...

Read More

Python - Get items in sorted order from given dictionary

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 250 Views

Python dictionaries contain key-value pairs that are unordered by default. Often, we need to display or process dictionary items in sorted order based on their keys. This article explores different methods to sort dictionary items. Using operator.itemgetter() The operator module provides itemgetter() function which can extract specific elements from tuples. Using itemgetter(0) sorts by keys, while itemgetter(1) sorts by values ? import operator data = {12: 'Mon', 21: 'Tue', 17: 'Wed'} print("Given dictionary:", data) print("Sorted by keys:") for key, value in sorted(data.items(), key=operator.itemgetter(0)): print(key, "->", value) Given ...

Read More

Collapsible Pane in Tkinter Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 1K+ Views

Tkinter is the GUI building library of Python. In this article, we will see how to create a collapsible pane using Tkinter. Collapsible panes are useful when you have a large amount of data to display on a GUI canvas but don't want it to be visible all the time. They can be expanded or collapsed as needed to save screen space. A collapsible pane typically consists of a toggle button and a frame that can be shown or hidden. When collapsed, only the toggle button is visible. When expanded, the frame containing additional widgets becomes visible. Creating ...

Read More

Binning method for data smoothing in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 1K+ Views

Data smoothing is a crucial preprocessing technique in statistical analysis that helps reduce noise and makes data more suitable for analysis. The binning method is one approach where we group data values into discrete intervals called bins, making continuous data easier to handle and analyze. Understanding Binning Binning involves creating ranges (bins) and assigning data values to these ranges. The upper boundary of each bin is excluded and belongs to the next bin. This helps in data discretization and noise reduction. Manual Binning Example Let's understand binning with a simple example ? # Given ...

Read More

ASCII art using Python pyfiglet module

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 2K+ Views

The pyfiglet module in Python allows you to create stylish ASCII art text with various fonts. This module transforms regular text into large, decorative ASCII representations that are perfect for banners, headers, or creative displays. Installation First, install the pyfiglet module using pip ? pip install pyfiglet Default Font Example The simplest way to create ASCII art is using the default font ? import pyfiglet # Text in default font result = pyfiglet.figlet_format("Python") print(result) ____ _ _ ...

Read More

Add one Python string to another

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 457 Views

String concatenation in Python combines two or more strings into a single string. Python provides several methods to add strings together, with the + operator and join() method being the most common approaches. Using the + Operator The + operator concatenates strings by combining them sequentially. This is the most straightforward method for joining strings ? first_string = "What a beautiful " second_string = "flower" print("Given string s1:", first_string) print("Given string s2:", second_string) # Using + operator result = first_string + second_string print("Result after adding strings:", result) Given string s1: What ...

Read More

Add list elements with a multi-list based on index in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 664 Views

When working with nested lists, you may need to add elements from a simple list to elements within a nested list based on their index positions. This operation pairs each element from the simple list with the corresponding sublist in the nested list and adds the simple list element to each item in that sublist. If the lists have different lengths, the operation is limited by the shorter list. Below are three efficient methods to accomplish this task. Using for Loop This method uses nested loops to iterate through both lists simultaneously. We take the length of ...

Read More
Showing 221–230 of 8,547 articles
« Prev 1 21 22 23 24 25 855 Next »
Advertisements