subjects

Dropdown Menu

Monday 15 February 2021

Data Types in Python

 Every value in python has a data type. Everything is an object in python programming. There are various datatypes in python. Some of the important types are listed below.

  1. Numbers.
  2. Strings.
  3. List.
  4. Tuple.
  5. Dictionary.
I. Python Numbers : Integers, Floating point numbers, Complex numbers and Boolean belong to Number category. They are defined as int, float, complex and bool class in Python.

1) Int : Integers can be of any length, it is only limited by the memory available. Integers are numbers without decimal values.
2) Float: A floating point number is accurate up to 15 decimal places. Integer and floating points are separated by decimal points. 1 is integer but 1.0 is floating point number.
3)Complex: Complex numbers are written in the form, a + bj, where a is the real part and b is the imaginary part. Here are some examples.
4) Boolean: These represent the truth values True, False. The Boolean type is plain sub type of integer where True behave as 1 False behave as 0.


II. Python Strings: String is sequence of characters. Strings, which can be expressed in several                 ways. They can be enclosed in single quotes ('...') or double quotes ("...") with the same result.     Strings are immutable, so we cannot modify string values.  Characters are stored into a string by 
using Indexing.     Like list and tuple, slicing operator [] can be used with string


III. Python List : List is an ordered sequence of items, which can be written as comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type. Like strings (and all other built-in sequence type), Lists can be indexed and sliced


IV. Python Tuple: Tuple is made up of data items with comma separated values enclosed within parentheses.
  •  Tuples are immutable sequences,
  • Tuple is typically used to store collections of heterogeneous data or homogeneous data items.
  •  Like strings (and all other built-in sequence type), tuple can be indexed and sliced.



V. Dictionaries : an unordered set of{ key: value} pairs, where keys are unique within a dictionary.





2 comments: