Built-in Methods

Python Write File

We have previously seen how we can read from a file in Python. Similarly writing to a file can also be achieved in Python programming. But, before we start writing to a file, we must ensure that the mode in which the file has been open allows it. Let us take a look using which […]

Python Write File Read More »

Find String Length in Python

We can find string length in Python using the built-in len() function. Let’s look at how this function works, and also let’s try finding the length of various types of Python strings using len(). Using len() Let’s look at some simple examples to illustrate len(). This prints 20 because it is the number of characters

Find String Length in Python Read More »

Python – Print to File

In this article, we shall look at some of the ways to use Python to print to file. Method 1: Print To File Using Write() We can directly write to the file using the built-in function write() that we learned in our file handling tutorial. Output (Assume that output.txt is a newly created file) Method

Python – Print to File Read More »

Python slice() function

Python slice() function returns a sliced object from the set of indexes of the input specified by the user in accordance with the arguments passed to it. Thus, it enables the user to slice any sequence such as Lists, Tuples, Strings, etc. Syntax: Start: (Optional) An integer that specifies the index to initiate the slicing

Python slice() function Read More »

Python chr() and ord()

Python’s built-in function chr() is used for converting an Integer to a Character, while the function ord() is used to do the reverse, i.e, convert a Character to an Integer. Let’s take a quick look at both these functions and understand how they can be used. The chr() function Syntax This takes in an integer

Python chr() and ord() Read More »

Python bytes()

Python bytes() is a built-in function which returns a bytes object that is an immutable sequence of integers in the range 0 <= x < 256. Depending on the type of object passed as the source, it initializes the byte object accordingly. Let’s look at how we can use this function in this article. Syntax

Python bytes() Read More »

Python print() function

Python print() function basically prints the given input or object to the output screen or the corresponding stream file. Syntax: Python print() function Arguments: Arguments Description Required/Optional object(s) An object or input string Required sep=’value‘ Specification on how the objects are to be separated.Default separator value is ‘ ‘ Optional end=’end_value’ Specifies what is to

Python print() function Read More »

Python input() function

It often happens that the developers/programmers need to accept the input from the user to process further with the application. Python provides a built-in-method to accept the input from the user. Python input() function accepts the input from the user. Python’s builtins.py contains the Python input() function. Syntax: The prompt is optional in the input()

Python input() function Read More »

Python zip() Function

Python zip() function stores data inside it. This function accepts iterable elements as input and returns an iterable as the output. If no iterable elements are provided to the python zip function, it returns an empty iterator. It thus aggregates elements from the iterables and returns iterables of tuples. Python Zip() Function Syntax: Python zip()

Python zip() Function Read More »