Found 10476 Articles for Python

How to convert float to integer in Python?

Gireesha Devara
Updated on 23-Aug-2023 18:42:17

2K+ Views

In python there are two number data types: integers and floats. In general integers do not have any decimal points and base value is 10 (i.e., Decimal). Whereas floats have decimal points. Python provides some built−in methods to convert floats to integers. In this article we will discuss some of them. Using the int() function The int() function converts the floating point numbers to integers, by removing the decimals and remains only the integer part. Also the int() function does not round the float values like 49.8 up to 50. Example In the example the data after the decimal ... Read More

How to convert an integer to a character in Python?

Gireesha Devara
Updated on 23-Aug-2023 18:36:02

37K+ Views

To convert an integer to a character in Python, we can use the chr() method. The chr() is a Python built−in method that returns a character from an integer. The method takes an integer value and returns a unicode character corresponding to that integer. Syntax char(number) Parameter The method takes a single integer between the range of 0 to 1, 114, 111. Return Value A unicode character of the corresponding integer argument. And it will raies a ValueError if we pass an out of range value (i, e. range(0x110000)). Also it will raise TypeError − for a non−integer argument. ... Read More

How to print out the first character of each list in Python?

Shriansh Kumar
Updated on 12-Jul-2025 23:57:50

5K+ Views

A Python list is a built-in, mutable datatype that stores multiple items or elements, separated by commas, within square brackets [ ]. The index of a list in Python starts from 0 up to length-1. We can retrieve/access elements at a particular index as follows - list_name[index] The given task is to write a Python program that prints the first character of each element in a list. But, before that, let's see some example scenarios: Scenario 1 For example, if our list contains string values, the output should be the first character of each string. Input: list = ... Read More

What is the #define Preprocessor in C++?

Jennifer Nicholas
Updated on 18-Jun-2020 13:05:52

558 Views

The #define creates a macro, which is the association of an identifier or parameterized identifier with a token string. After the macro is defined, the compiler can substitute the token string for each occurrence of the identifier in the source file.#define identifier token-stringThis is how the preprocessor is used. The #define directive causes the compiler to substitute token-string for each occurrence of identifier in the source file. The identifier is replaced only when it forms a token. That is, identifier is not replaced if it appears in a comment, in a string, or as part of a longer identifier.example#include #define ... Read More

Can we use pass statement in a Python if clause?

Malhar Lathkar
Updated on 01-Sep-2025 14:48:06

168 Views

Yes! We can use a pass statement in a Python if clause. This is used when a statement is required syntactically, but you do not want any command or code to execute. It represents a piece of code that will be added later, but initially, a placeholder is required to ensure the program runs without errors. And the if statement in Python evaluates whether a condition is true or false. So, the pass statement can be used in an if as well as an else block. Pass Statement in If Clause In this section, we will see ... Read More

What does 'not in' operator do in Python?

Malhar Lathkar
Updated on 26-Feb-2020 10:40:31

346 Views

In Python, in and not in operators are called membership operators. Their purpose is to check if an object is a member of a certain sequence object like string, list, or tuple. The not in operator returns false if object is present in sequence, true if not found>>> 'p' not in 'Tutorialspoint' False >>> 'c' not in 'Tutorialspoint' True >>> 10 not in range(0,5)

What does \\\'is\\\' operator do in Python?

Disha Verma
Updated on 21-Apr-2025 16:34:55

3K+ Views

The "is" operator in Python is an identity operator. This operator checks whether two variables refer to the same object in memory. It returns boolean values as a result. Each object in the computer's memory is assigned a unique identification number (id) by the Python interpreter. Identity operators check if the id() of two objects is the same. The 'is' operator returns false if id() values are different and true if they are the same. Syntax of Python (is) Operator The "is" operator follows the following syntax in Python: variable1 is variable2 The "is" operator ... Read More

What is Python equivalent of the ! operator?

Gireesha Devara
Updated on 09-Sep-2023 09:48:50

3K+ Views

In some languages like C / C++ the "!" symbol is used as a logical NOT operator. !x it returns true if x is false else returns false. The equivalent of this "!" operator in python is logical NOT, It also returns true if the operand is false and vice versa. Example In the Following example the variable operand_X holds a boolean value True, after applying the not operator it returns False. operand_X = True print("Input: ", operand_X) result = not(operand_X) print('Result: ', result) Output Input: True Result: False Example For False value the ... Read More

What does these operators mean (** , ^ , %, //) ?

Disha Verma
Updated on 18-Apr-2025 14:10:06

547 Views

In Python, there are various types of operators used to perform specific functions, such as (**), (^), (%), and (//). The (**) operator represents exponentiation, (^) represents bitwise XOR, (%) represents the modulus operation, and (//) represents floor division. In this article, we will understand the workings of these operators. Exponentiation Operator (**) The exponentiation operator (**) is used to raise a number to a power. This operator works the same as the Python pow() method. In exponentiation, you need two numbers: the first is the base (the number you want to raise), and the second is ... Read More

What is the difference between = and == operators in Python?

Disha Verma
Updated on 18-Apr-2025 14:15:37

2K+ Views

The symbols "=" and "==" look similar but have different meanings and usability in Python. The "=" symbol is the assignment operator, and the "==" symbol represents a comparison operator. In this article, we will understand the difference between these two and how to use them. The "=" Operator The "=" operator in Python is the assignment operator. It is used to assign a value to a variable. You put the variable on the left side and the value or expression on the right side. The value on the right is stored in the variable on the ... Read More

Advertisements