Programming Basics- Data Types

Programming Basics- Data Types

Data Types in Programming

Introduction

  • In programming, data types are used to determine the kind of value a variable can have.
  • Understanding different data types is fundamental to being able to successfully create and manipulate variables in a program.

Integer

  • Integer, often shortened to int, refers to a number that is not a fraction; it is a whole number.
  • This data type is used when you want to store whole numbers, either positive or negative.
  • In Python, there is no limit to the size of an integer.

Float

  • Float refers to a number that is not a whole number; it contains decimal points.
  • This data type is used when you need values of varying precision or numbers with decimal places.

Boolean

  • A boolean has two possible values: True or False.
  • This simple binary option is incredibly useful when it comes to decision-making in programs.

String

  • String often refers to a sequence of characters.
  • They are usually used to represent words or text in a program.
  • A string in Python is enclosed either by single quotation marks, or double quotation marks.

Lists and Arrays

  • Lists and arrays are similar data types that store a series of values.
  • Unlike the single-value data types of Integer, Float, Boolean, and String, lists and arrays are capable of storing multiple values at once.
  • The major difference between lists and arrays is that lists can store different data types, while arrays house multiple values of the same data type.

Constants

  • A constant is a type of variable whose value cannot be changed after it’s defined.
  • It’s typically used to set the value of something that needs to remain constant throughout the program.

Variables

  • Variables are containers for storing data values. A variable is initialised with a data type, and any value that is stored in it must be compatible with its initialised type.
  • In a program, variables are defined with a unique name, which is used to refer back to the stored value without divulging the value itself.