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!

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.

Ubuntu Server Admin

Recent Posts

How to Troubleshoot and Optimize Ubuntu Startup: Manage Systemd Services for Faster Boot Time

Optimizing your Ubuntu startup is essential for a seamless user experience and efficient system performance.…

34 minutes ago

Repeat Linux Commands Every X Seconds for Real-Time Monitoring, Automation & Precise Scheduling

Linux administrators and power users often need to run commands repeatedly. Whether you’re monitoring system…

35 minutes ago

Monitor and Optimize Memory Usage on Ubuntu 22.04 for Peak Performance

If you are an Ubuntu 22.04 user, appreciating its user-friendly design and robust capabilities as…

1 day ago

Troubleshooting and Resolving Audio Issues in Ubuntu 22.04

Experiencing a sudden loss of audio on your Ubuntu 22.04 system can be incredibly frustrating.…

1 day ago

Monitor GPU Usage in Ubuntu 22.04 for Optimal Performance

Unlike Windows, Ubuntu’s default system monitoring tool does not natively display real-time GPU usage. For…

1 day ago

How to set up a UFW on Ubuntu 22.04

In today’s fast-paced digital world, keeping your system safe is crucial. One of the best…

1 day ago