Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 649 of 2109
How to create a zip file using Python?
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 MoreHow to create a tar file using Python?
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 MoreHow an entire file is read into buffer and returned as a string in Python?
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 MoreHow to print characters from a string starting from 3rd to 5th in Python?
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 MoreWhat is the maximum size of list in Python?
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 MoreWhat is the maximum length of string in Python?
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 MoreWhat is the maximum value of float in Python?
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 MoreHow to sort a dictionary in Python by values?
Python allows dictionaries to be sorted using the built-in sorted() function. In this article, we will explore different ways to sort a dictionary in Python by its values. Using itemgetter() Method The itemgetter() method from the operator module provides an efficient way to sort dictionaries by values. It returns a callable object that fetches an item from its operand using the provided index ? from operator import itemgetter dictionary = { 'b': 2, 'a': 1, 'd': 4, 'c': 3 ...
Read MoreHow to sort a dictionary in Python by keys?
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 MoreHow to print all the keys of a dictionary in Python
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