Datatypes in python
DATATYPES
Example
Getting the Data Type
•x=5
print(type(x))
MATCH
• int → Stores textual data.
• float → A collection of unique items.
• str → Represents decimal numbers.
• bool → Represents whole numbers.
• list → Represents a true or false value.
• tuple → Immutable ordered collection of
items.
• dict →An ordered collection of items.
• set → A collection of key-value pairs.
ANSWER
• int → Represents whole numbers.
• float → Represents decimal numbers.
• str → Stores textual data.
• bool → Represents a true or false value.
• list → An ordered collection of items.
• tuple → Immutable ordered collection of
items.
• dict → A collection of key-value pairs.
• set → A collection of unique items.
Setting the Data Type
Example Data Type Try it
x = "Hello World" str Try it »
x = 20 int Try it »
x = 20.5 float Try it »
x = 1j complex Try it »
x = ["apple", "banana", list Try it »
"cherry"]
x = ("apple", "banana", tuple Try it »
"cherry")
x = range(6) range Try it »
x = {"name" : "John", "age" dict Try it »
: 36}
x = {"apple", "banana", set Try it »
"cherry"}
x = frozenset({"apple", frozenset Try it »
"banana", "cherry"})
x = True bool
Boolean Values
print(10 > 9)
print(10 == 9)
print(10 < 9)
OUTPUT
True
False
False
TYPE Casting
INTEGERS
x = int(1) # x will be 1
y = int(2.8) # y will be 2
z = int("3") # z will be 3
FLOAT
x = float(1) # x will be 1.0
y = float(2.8) # y will be 2.8
z = float("3") # z will be 3.0
w = float("4.2") # w will be 4.2
STRINGS
x = str("s1") # x will be 's1'
y = str(2) # y will be '2'
z = str(3.0) # z will be '3.0'