In Easy Steps Articles

September 27, 2021

Here’s how to recognize the four essential types of data you can represent when coding a computer program…

There are four essential types of data you can represent and that can be stored in variables when coding a computer program. Although variables in the Python language can store any type of data it is important to understand the different types as you will sometimes need to convert from one type to another in your code:

  • Strings are simply any collection of characters you can enter from the computer keyboard, grouped together within quote marks.
  • Variables recognize a value being assigned to it as belonging to the str “class” if that value is enclosed within quote marks.
  • Numbers are any numeric value you can enter from the keyboard but are defined by the inclusion or omission of a decimal point. Variables recognize a numeric value being assigned to it as belonging to the int “class” if that value has no decimal point or as belonging to the float class if it does indeed have a decimal point.
  • Booleans are a logical truth value. Variables recognize a Boolean value being assigned to it as belonging to the bool “class” by the keywords True and False, or if that value evaluates to True or False.

In Python programming you can easily discover the type of data stored within a variable by specifying that variable’s name within the parentheses of the built-in type() function.

This extract is from Coding for Beginners in easy steps. Get the book and learn a new skill!

£10.99

192 pages
By Mike McGrath
ISBN: 9781840786422

Sign up to our

Newsletter

Our newsletters inform you of new and forthcoming titles, handy tips, and other updates and special offers. You can opt out anytime.

"*" indicates required fields

By In Easy Steps Team

Share

We are sorry to let you go...

Would you mind giving us your feedback or reason of cancelling the subscription?

 

"*" indicates required fields

Hidden
Hidden
Hidden
Reason For Cancellation*
Hidden