0% found this document useful (0 votes)
3 views

Lecture 3 a Handout Datatypes

Uploaded by

Barathraj D18
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lecture 3 a Handout Datatypes

Uploaded by

Barathraj D18
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Data Types in Python Programming

In Python, data types define the kind of data a variable can store. They determine how the data is
stored, manipulated, and used in programs. Python is dynamically typed, meaning you don’t need to
specify the data type of a variable explicitly—it’s inferred from the value you assign.

Categories of Data Types in Python


Python has several built-in data types, grouped into categories:

1. Numeric Types
Used to represent numbers:
• int (Integer): Whole numbers, both positive and negative.
Example: x = 10
• float (Floating-Point): Numbers with decimals.
Example: y = 3.14
• complex: Numbers with a real and imaginary part.
Example: z = 2 + 3j

2. Sequence Types
Used to store collections of items:
• str (String): A sequence of characters enclosed in single, double, or triple quotes.
Example: name = "Python"
• list: A mutable, ordered collection of items.
Example: numbers = [1, 2, 3, 4]
• tuple: An immutable, ordered collection of items.
Example: coordinates = (10, 20)

3. Boolean Type
Represents truth values:
• bool: Can be either True or False.
Example: is_valid = True

4. Mapping Type
Used to store key-value pairs:

1
• dict (Dictionary): A mutable, unordered collection of key-value pairs.
Example: person = {"name": "Alice", "age": 30}

5. Set Types
Used to store unique, unordered items:
• set: A mutable collection of unique items.
Example: unique_numbers = {1, 2, 3}
• frozenset: An immutable version of a set.
Example: frozen = frozenset({1, 2, 3})

6. None Type
Represents the absence of a value:
• None: Used to indicate a null or undefined value.
Example: x = None

Type Conversion
You can convert between data types using built-in functions like int(), float(), str(), etc. For
example:
x = "42" # String
y = int(x) # Convert to integer

You might also like