.png)
1. Numbers
Python has three types of numeric data types: integers, floating-point numbers, and complex numbers.- Integers: These are whole numbers, positive or negative, without decimal points. For example, 1, 2, 3, -4, -5, etc.
- Floating-Point Numbers: These are numbers with decimal points or numbers in exponential form. For example, 2.5, 3.14, 1.2e-5, etc.
- Complex Numbers: These are numbers with a real part and an imaginary part. For example, 3+4j, 1-2j, etc.
Strings
Strings are sequences of characters enclosed in either single or double quotes.For example:
name = "John" sentence = "The quick brown fox jumps over the lazy dog"
Lists
Lists are a collection of items, and each item can be of any data type. The items in a list are separated by commas and enclosed in square brackets.For example:
numbers = [1, 2, 3, 4, 5] fruits = ["apple", "banana", "cherry"]
Tuples
Tuples are similar to lists, but they are immutable, which means their contents cannot be changed after creation.For example:
coordinates = (10, 20) colors = ("red", "green", "blue")
Dictionaries
Dictionaries are a collection of key-value pairs enclosed in curly braces.For example:
person = {"name": "John", "age": 30, "gender": "Male"}
Boolean
Boolean data types represent truth values, which can either be true or false.For example:
is_raining = True is_sunny = False
In conclusion, Python provides a rich set of data types that can be used to represent different types of data. Understanding these data types is crucial in writing efficient and error-free Python code.
0 Comments