Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

Python Data Types

Python has several built-in data types. Here’s an overview with examples:


Numbers

  • int: Integer values
  • float: Floating-point numbers
  • complex: Complex numbers
x = 5      # int
y = 3.14   # float
z = 2 + 3j # complex

Strings

  • Immutable sequences of Unicode characters
  • Support slicing, concatenation, and many methods
s = 'hello'
print(s[1:4])      # 'ell'
print(s.upper())   # 'HELLO'

Lists

  • Ordered, mutable sequences
  • Allow duplicates and mixed types
lst = [1, 'a', 3.14]
lst.append(42)
print(lst)

Tuples

  • Ordered, immutable sequences
  • Allow duplicates and mixed types
tpl = (1, 2, 3)
print(tpl[0])

Sets

  • Unordered collections of unique, hashable items
  • No duplicates, mutable
s = {1, 2, 3}
s.add(2)  # No effect, 2 already present
print(s)

Dictionaries

  • Unordered collections of key-value pairs
  • Keys must be unique and hashable
d = {'a': 1, 'b': 2}
d['c'] = 3
print(d)

Type Checking

print(type(3.14))      # <class 'float'>
print(isinstance(d, dict))  # True

Type Conversion

print(int('42'))      # 42
print(list('abc'))    # ['a', 'b', 'c']