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

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)