Print Characters from a String Starting from 3rd to 5th in Python

Sarika Singh
Updated on 29-May-2025 03:32:32

10K+ Views

Python uses arrays of bytes called strings to represent Unicode characters. In Python, string indexing ranges from 0 to n-1, where n is the length of the string. In a string of size n, the characters can be retrieved from 0 to n-1. For Example, we can index the string "Coding" as 0, 1, 2, 3, 4, 5, in which the length of the string is 6. The first character in the string "Coding" is represented by the number 0, and the characters o, d, i, n, and g are represented by the numbers 1, 2, 3, and 5, respectively. ... Read More

Create a TAR File Using Python

Sarika Singh
Updated on 29-May-2025 03:23:40

14K+ Views

TAR stands for Tape Archive Files. The Tar files are the archive files which allows us to store numerous files in a single file. A Open-source software is distributed using tar files. Tar files typically end in .tar later they can be compressed using tools such as gzip which have the file ending as tar.gz. Different file modes to create a tar file Here are the available different 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 ... Read More

Difference Between os.open and os.fdopen in Python

Sumana Challa
Updated on 28-May-2025 19:57:42

1K+ Views

The open() function is a built-in Python function that helps you work with files, however, the os module offers low-level file handling functions that give more control over how files are opened and managed, two of such function from the os module are os.open() and os.fdopen(). The key difference between both os.open() and os.fdopen() functions is that os.open() is used to open a file and extract its file descriptor, while os.fdopen() is used to wrap an existing file descriptor and create a file object. What is os.open() Function? The os.open() function in the os module opens the specified file and returns a ... Read More

Change the Owner of a File Using Python

Sumana Challa
Updated on 28-May-2025 19:54:11

1K+ Views

Changing the ownership of a file is to transfer the file's ownership from one user to another. This is mainly to specify who has control over modifying, deleting, or setting permissions for the file. Before you change the ownership of a file, make sure you have administrative privileges, and the methods discussed below only work on Linux.To change the ownership of a file from one user to another in Python, we can use the following ways - Using os.chown() Method The os.chown() method is used to change the owner and group ID of a file. To this method, we need to ... Read More

Open Binary File in Read and Write Mode with Python

Sumana Challa
Updated on 28-May-2025 19:23:01

3K+ Views

Binary file is a file that consists of a series of 1's and 0's. This is typically used to represent data such as images, audio, video, etc. To open the binary files in read and write mode, Python provides an in-built function, which is the open() function. The open() Function  The Python open() function is a built-in function that is used to open a file. This method accepts a string value representing a file path (or, name) as a parameter and returns the object of the specified file. In addition to the file path, we can also pass another parameter named ... Read More

Multiply Large Numbers Using Python

Sumana Challa
Updated on 28-May-2025 19:11:48

3K+ Views

You can multiply large numbers in Python directly without worrying about speed. Python supports a "bignum" integer type which can work with arbitrarily large numbers. In Python 2.5+, this type is called long and is separate from the int type, but the interpreter will automatically use whichever is more appropriate. As long as you have version 2.5 or better, just perform standard math operations, and any number which exceeds the boundaries of 32-bit math will be automatically (and transparently) converted to a bignum. To multiply large numbers in Python, we can use the basic multiplication operator or use the fractions ... Read More

Tokens, Identifiers, and Keywords in C++

Akansha Kumari
Updated on 28-May-2025 19:05:08

968 Views

In C++, tokens, identifiers, and keywords all are fundamental elements of a program. Tokens are the smallest units of code which are combine together to form complete program, where both keywords and identifiers are the types of tokens. The keywords are reserved words in the language, where each provides separate meanings to code and cannot be used as names by the programmer, whereas identifiers are names defined and used by programmers to represent variables, function or other user-defined elements. In this article, we will learn about all three in detail. Tokens in C++ A token is the smallest element of ... Read More

What are Type Qualifiers in C++

Akansha Kumari
Updated on 28-May-2025 19:04:29

2K+ Views

A type qualifier is a keyword in C++ that is applied to a variable, function, pointer, or parameter to add an extra feature or quality to it. For example, const int is a qualified type representing a constant integer, while int is an unqualified type, which is simply just an integer. Type qualifiers are a way of expressing additional information about a value through the type system, which ensures correctness in the use of the data. 1. The const Qualifier This is used to define a variable (or object) as constant, which means its value cannot be changed or modified ... Read More

Difference Between #define and const Keyword in C++

Akansha Kumari
Updated on 28-May-2025 19:04:05

405 Views

In C++, both #define and const are used to define constants in a program. The #define is a preprocessor directive that creates macros with their fixed values whereas const is a keyword which declare value of variable as constant, meaning its value cannot be changed after intialization. Therefore they have different use cases in different scenarios. In this article, we will learn the differences between these two in detail. #define in C++ The #define is a preprocessor directive that is used to define or assign macros ( name or string ) with a constant value. So wherever the macro occurs ... Read More

Convert String to Char Array in C++

Nishu Kumari
Updated on 28-May-2025 18:05:05

4K+ Views

A string in C++ is a group of characters written inside double quotes like "Hello" and characters are the single letters or symbols in a string. Converting a string to a char array means putting each character into a simple list (array) of characters. In this article, we will show you how to convert a string to a character array in C++. For example, if we have the string "Hello@TP", converting it to a char array means storing each character 'H', 'e', 'l', 'l', 'o', '@', 'T', and 'P' separately in an array.How to Convert a String into a Character ... Read More

Advertisements