Programming Articles

Page 660 of 2547

How are files added to a tar file using Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 3K+ Views

Python offers a built-in module named tarfile, which allows developers to create, read, and modify tar archives (standard Unix tarballs). We can use this module to compress multiple files into a single archive, with or without compression. File Modes for Creating Tar Archives Here are the available file modes to create a tar file using Python − "w": Write a tar archive without compression. "w:gz": Write a gzip-compressed archive. "w:bz2": Write a bzip2-compressed archive. "w:xz": Write an xz-compressed archive (Python 3.3+). Adding a Single File to ...

Read More

How to create a zip file using Python?

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 72K+ Views

ZIP is a widely used file format that compresses one or more files into a single archive file. This file format helps to reduce storage space and simplifies sharing or save backup of large data files. ZIP archives usually have a .zip file extension and are commonly used across different platforms. Compressed ZIP files reduce the size of the original directory by applying a compression algorithm. This results in faster file sharing over a network as the size of the ZIP file is significantly smaller than the original file. Python Modules for Creating ZIP Files In Python, ...

Read More

How to create a tar file using Python?

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 15K+ Views

TAR stands for Tape Archive Files. Tar files are archive files that allow us to store multiple files and directories in a single file. Open-source software is commonly distributed using tar files. Tar files typically end in .tar and can be compressed using tools such as gzip, resulting in files ending with .tar.gz. File Modes for Creating Tar Files Here are the available file modes to create tar files using Python's tarfile module ? "w": Write a tar archive without compression. "w:gz": Write a gzip-compressed archive. "w:bz2": Write a ...

Read More

How an entire file is read into buffer and returned as a string in Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 9K+ Views

When dealing with files in Python, we can read the entire file into memory as a string or process it in chunks using a buffer. This article explores different approaches to read files efficiently, including reading the entire content at once and using buffered reading for large files. Syntax The basic syntax for reading a file with a specified buffer size is ? with open('filename', 'r') as file: chunk = file.read(buffer_size) Where: filename: The path of the file 'r': Read ...

Read More

How to print characters from a string starting from 3rd to 5th in Python?

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 10K+ Views

Python strings use indexing to access individual characters, starting from index 0. To extract characters from the 3rd to 5th position, we can use string slicing with different approaches. String Indexing Basics In Python, string indexing starts from 0. For example, the string "Coding" has indices 0, 1, 2, 3, 4, 5 for characters C, o, d, i, n, g respectively. text = "Coding" print(f"Length: {len(text)}") print(f"First character (index 0): {text[0]}") print(f"Third character (index 2): {text[2]}") Length: 6 First character (index 0): C Third character (index 2): d Method 1: Using ...

Read More

What is the maximum size of list in Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 6K+ Views

In Python, a list is a dynamic array that can be expanded in size as needed. The maximum size of a list is limited by the system's memory and the platform's architecture. In this article, we will explore how to determine the maximum size of a list in Python. Understanding Python List Limits The size of a list in Python is not restricted by any fixed value set in the language itself. Instead, it depends on several factors ? Available system memory (RAM) System architecture (32-bit or 64-bit) The value of sys.maxsize Maximum Size ...

Read More

What is the maximum length of string in Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 8K+ Views

In Python, strings are dynamic and can grow to very large sizes, limited only by the system's available memory. Unlike some other languages, Python does not define a strict upper bound on string length. The practical maximum length of a string depends on the platform and memory constraints. In this article, we will explore how to determine the theoretical maximum string length in Python and understand the practical limitations. Maximum Theoretical String Length Python strings are stored as sequences of Unicode characters, and the maximum size of a Python object is typically constrained by the value of ...

Read More

What is the maximum value of float in Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 1K+ Views

In Python, floating-point numbers are implemented using double-precision, i.e., 64-bit format, as per the IEEE 754 standard. These floats have a finite range and precision. The maximum value that a float can represent depends on the platform, but can be accessed using the sys.float_info attribute. Maximum Value of Float using sys.float_info The sys.float_info object provides details about the float implementation on the current platform. The attribute float_info.max gives the largest positive floating-point number representation. Example Here we use float_info.max attribute from the sys.float_info object to get the maximum float value in Python − ...

Read More

How to sort a dictionary in Python by keys?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 771 Views

Python allows dictionaries to be sorted using the built-in sorted() function. Although dictionaries in Python 3.7+ preserve insertion order, we can still create a new dictionary sorted by its keys using various methods. In this article, we will explore different ways to sort a dictionary in Python by its keys. Using sorted() with Dictionary Comprehension The most Pythonic way to sort a dictionary by keys is using dictionary comprehension with the sorted() function. This creates a new dictionary with keys in alphabetical order − data = { 'zebra': 26, ...

Read More

How to print all the keys of a dictionary in Python

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 108K+ Views

A Python dictionary is an unordered collection of data values that stores key-value pairs. In this article, we will explore various methods to print all the keys of a dictionary in Python. Using dict.keys() Method The dict.keys() method returns a dictionary view object containing all the keys. This is the most direct way to access all keys in a dictionary ? Example dictionary = { 'Novel': 'Pride and Prejudice', 'year': '1813', 'author': 'Jane Austen', 'character': 'Elizabeth Bennet' } ...

Read More
Showing 6591–6600 of 25,466 articles
« Prev 1 658 659 660 661 662 2547 Next »
Advertisements