Data Types

In Python, data types are one of the following:

  • Numbers

  • Strings

  • Lists

  • Tuples

  • Dictionaries


Numbers

Numbers in python can be: int, float, and complex:

num1 = 5
num2 = 4.0
num3 = 3.14j

print(type(num1))
print(type(num2))
print(type(num3))

Output:

<class 'int'>
<class 'float'>
<class 'complex'>

Strings

Strings in python are contiguous sets of characters represented in either single or double quotation marks. They can be manipulated using slicing, concactenating, and etc like so:

str = 'Hello World!'

print(str)          # Prints complete string
print(str[0])       # Prints first character of the string
print(str[2:5])     # Prints characters starting from 3rd to 5th
print(str[2:])      # Prints string starting from 3rd character
print(str * 2)      # Prints string two times
print(str + "TEST") # Prints concatenated string

Output:

Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!TEST

For Lists, Dictionaries, and Tuples, please see the official documentation.