Image for post
Image for post

Data types are variables that represent a reserved space in memory. Python is dynamically-typed so the declaration happens automatically when you assign a value to a variable.

A string is a set of characters inside quotation marks. You can use single or double quotes. In Python strings are immutable, that’s why string methods usually return a new string.

str = ‘Hello world’

A set is an unordered collection of unique objects. There are two types of set: sets and frozen sets which are immutable.

colors = {‘orange’, ‘yellow’, ‘red’}

Numbers are divided in four types: int, float, complex and long. Conversions might be necessary sometimes.

int_num = 3
float_num = 6.7
complex_num = 3.14j
long_num = 1234567L

Lists are similar to arrays in C. A list contains items separated by commas enclosed in square brackets. You can have multiple datatypes in the same list.

list = [100,’abc’,6.7,’f’]

A dictionary consists of key-value pairs. It is enclosed in curly braces and values can be accessed using square brackets.

dict = {‘name’:’John’,’age’:21}

Tuples are similar to lists but they are immutable and enclosed in parentheses.

tuple = (100,’abc’)

Developer and writer working in technology and entertainment.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store