Data Types In Python

  • In Python, data types are used to define the type of data that a variable can hold.
  • Data types in programming represent the kind of value that a variable or expression can hold.
  • Let us learn some common data types.

Numeric

  • int: Integer type represents whole numbers.
  • float: Floating-point type represents real numbers with a fractional part.
  • complex: Complex type represents numbers with both a real and an imaginary part.

Set

  • Set is an unordered collection of unique elements.

Dictionary

  • Represents an unordered collection of key-value pairs, and allows operations like adding, accessing, and removing elements based on keys.

Boolean

  • Boolean type represents either True or False.

Sequence

  • List: List is an ordered and mutable collection of elements.
  • Tuple: Tuple is an ordered and immutable collection of elements.
  • String: It represents a sequence of characters and is used to represent textual data.

NUMBERS

  • Python provides several numeric data types to represent numbers, including integers (int), floating-point numbers (float), and complex numbers (complex).

1. INTEGERS ('int') :

  • Integers represent whole numbers without any fractional part.
  • They can be positive or negative.
  • They do not include a decimal point.

2. FLOAT ('float') :

  • The float data type (float) in Python is used to represent floating-point numbers, which are real numbers with a fractional part.
  • Floats can be positive or negative and can include a decimal point.

INT VS FLOAT

  • For age , you will use int datatype , there’s nothing like 9.82 years old. One cannot consider age to be a float datatype.
  • Integers are commonly used for counting, indexing, and representing discrete quantities.
  • Floating-point numbers are used to represent continuous quantities, real-world measurements like price or rate.
  • Float is more powerful because it can handle a number with fraction or decimal whereas “int” can’t.

Basic Arithmetic Operations

Rounding and precision

  • The round() function is used to round a number to a specified number of decimal places or to the nearest whole number.

3. Complex

  • Complex numbers are written with a “j” as the imaginary part.
  • Let us consider an example.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x