Categories: TutorialsUbuntu

Python bool() Function in Linux

Introduction

In Python, the input() function is used so that the user can input data. Whatever you enter, this function will convert it to a string. Even if you enter a number, the function will convert it to a string.

The following article is a detailed guide on how to use the input() function in Python as we go through the section below.

Example

print ("What is your name?")

x = input()

print("You are " + x + ", aren't you?")

For example, I will enter the name Python. Output:

What is your name?

You are Python, aren’t you?

Definition

input() function allows you to input data.

The syntax

input(data)
Parameter Values:

data: a string. For example: name, number, …

More
Sponsored
example

Example 1: Basic input() function

print ("Enter your mother name:")

x = input()

print("What a beautiful name!")

Output:

Enter your mother name:

What a beautiful name!

Example 2: Plus 1. Because the function will convert the input to a string. So if you want to input as int then use int()

Sponsored
print("Enter a number")

x = int(input())

plus = x + 1

print(plus)

Output:

Enter a number: 11

12

Example 3: Parity check program

def check(x):

return (bool(x % 2 == 0))

print("Enter a number")

x = int(input())

if (check(x)):

print("It is an even number")

else:

print("It is an odd number")

Output:

Enter a number: 8

It is an even number

Conclusion

Hope you understand our tutorial on how to use the input() function in Python.

Thanks for reading!

Ubuntu Server Admin

Recent Posts

IBM LinuxONE 5 and Ubuntu Server, a great combination from day one

Today, IBM announced the launch of their latest server: the new IBM LinuxONE Emperor 5.…

4 hours ago

Ubuntu Weekly Newsletter Issue 890

Welcome to the Ubuntu Weekly Newsletter, Issue 890 for the week of April 27 –…

21 hours ago

Ubuntu IoT Day in Singapore – Unlock compliant and scalable innovation in edge AI

Singapore | May 27, 2025 | Full-day event How do you build robust, performant edge…

1 day ago

Kolla Ansible OpenStack Installation (Ubuntu 24.04)

Kolla Ansible provides production-ready containers (here, Docker) and deployment tools for operating OpenStack clouds. This…

4 days ago

Canonical announces first Ubuntu Desktop image for Qualcomm Dragonwing™ Platform with Ubuntu 24.04

This public beta enables the full Ubuntu Desktop experience on the Qualcomm Dragonwing™ QCS6490 and…

5 days ago

The long march towards delivering CRA compliance

Time is running out to be in full compliance with the EU Cyber Resilience Act,…

5 days ago