DEV Community

Cover image for Python3 programming - Exercise 3 - More on data types and comments
Michael Otu
Michael Otu

Posted on • Edited on

1

Python3 programming - Exercise 3 - More on data types and comments

More on data types and comments

There are other data types other than those mentioned earlier in Exercise 2 (Data Types). We shall discuss the boolean data type.

This data type can only be True or False. Boolean values are generated when values are compared or when there is a condition. Eg 1 < 2 is True, 1 > 2 is False .

Examples

is_online = True
is_swift = True
is_human = False
Enter fullscreen mode Exit fullscreen mode

Note

Boolean values are case sensitive. Upper-case T for True and F for False , in python.

Comment

A comment is a piece of text that mostly should tell why or what we are trying to achieve. The # symbol, placed ( inserted) at the beginning of the line, comments the line ( the line is ignored by the interpreter).

Examples

# Hello world program
# Display Hello world for the user to see
# Using the print function
print("Hello world")
Enter fullscreen mode Exit fullscreen mode

The first three lines starting with # are comments. A comment is ignored during execution. You can also comment out some lines during debugging.

Note

Whatever that comes after the # would be ignored.
print('hello world') # greetings , greetings would be ignored.

Practicals

  1. In Exercise 2 (Data Types), add comments to your solutions to give the why/what the line is doing or meant to do ( remember that not all lines need a comment if the code is descriptive itself).

    • How many comments are there in the code below?
    • Which line numbers, would be displayed and why? practicals

Summary

  • A boolean value is True or False.
  • These values are generated during the comparison of two or more values.
  • A comment is supposed to explain, "the" what or why in the code ( line)
  • We can also use it to state how we want to reach our solution
  • Use # to create a comment

Sentry image

Make it make sense

Make sense of fixing your code with straight-forward application monitoring.

Start debugging →

Top comments (0)

Tiger Data image

🐯 🚀 Timescale is now TigerData: Building the Modern PostgreSQL for the Analytical and Agentic Era

We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.

So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.

Read more

👋 Kindness is contagious

If this **helped, please leave a ❤️ or a friendly comment!

Okay