Skip to Main Content

Learning Python: Part I: Object Types

A beginner's guide to Python programming.

Explanation

Course Instructions Part I:

Welcome to the first part of the learning python self-paced course.  On this page, we will learn about different basic objects in Python.  Below is a brief description of what object types are and the basic objects you will use while coding.  Go through the different tabs below: Introduction, Numeric Types, Dynamic Typing, Strings, Lists, Dictionaries, and Tuples. Under the Sample Code subheading you will find a link to get to the code, so you can start learning hands-on.

Object Types

Object Types

What is it?

In Python, everything is an object and the object type refers to the different kinds of objects. Basic types that have defined values include numeric, text, Boolean, sequences, lists, dictionaries, etc.

Why it matters?

It is essential to know what sort of a object type you are working with so that you can determine what functions will work with that object type.

Example:

X = 4             # this is a number object

X.upper()         # this will not work because the function upper (capitalizes all letters) is meant for string objects

                  # This code will result in an error.

Object Types

Introduction

Each of these tabs has a short introduction of a concept with a corresponding Jupyter Notebook (below under Sample Code) that will teach you concepts about that object type.  Go through them in the same order as the tabs.  

Basic Syntax

In order to create a specific object type, there is a certain syntax that must be used.  For example: 

X = 4                      # number

S = 'Hello'                # string

B = True                   # Boolean

L = [1, 2, 3, 4]           # list

T = (1, 2, 3)              # tuple

D = {'fruit': 'apple', 'color': 'red'}  # dictionary

Y = {1, 2, 2, 3}           # set

Sample Code

This sample code goes through more detail of the syntax and other functions used for the various object types.  Go through it carefully and try modifying the code to see what happens. You can get the code from:

 

Video

References

Here is a beginner’s cheat sheet.

If you want to learn more about Markdown, here is a cheat sheet.

What is it?

Numeric type objects are objects that involve numbers.  There are different types of numbers such as integers, floats, exponents, complex numbers, etc. 

Basic Syntax

In order to create a numeric type you use a different syntax depending on the number type.  For example: 

I = 4           # integer

F = 3.14        # float

E = 2.5e-4      # exponent (scientific notation)

C = 1 + 3j      # complex

Why it Matters?

Numeric types are important because they are the foundation of the data you will most likely analyze.  Understanding what type of number object is important in order to avoid errors.  For example:

X = 4           # This is designated as an integer

Y = X + 0.1

Y               # This is now a float. X is still an integer.
[output] 4.01

Sample Code

This sample code goes through more detail of the syntax and other functions used for the various object types.  Go through it carefully and try modifying the code to see what happens. You can get the code from:

 

Video

References

Here are some Python cheat sheets:

What is it?

Dynamic typing is the process of creating variables and allocating memory for that information. 

Why it Matters?

You need to keep track of which variables are assigned to what data type. For example:

X = 4

Y = X

Y  # it is now 4

 

[output] 4

or

N = [1, 2, 3]

M = N
P = N.copy()

N[0] = 99

print(N)
print(M) # Changing N also changes M because they are linked.
print(P) # The copy function allows for a new list to be created that is not linked to the original.

 

[output] [99, 2, 3]

[output] [99, 2, 3]

[output] [1, 2, 3]

Sample Code

This sample code goes through more detail of the syntax and other functions used for the various object types.  Go through it carefully and try modifying the code to see what happens. You can get the code from:

Video

References

Here are some Python cheat sheets:

What is it?

String type objects are characters or 'strings' of text that can be manipulated or even analyzed if necessary.

Basic Syntax

In order to create a string type you use quotes (') or double quotes (").  For example: 

S = 'String'                 # You can use single quotes.

Sen = "This is also a string."  # Or double quotes

E = "This will not work.'    # But not both. Make sure you are consistent. This will yield an error.

Why it Matters?

A lot of data can be in text format including the inputs into Large Language Models (LLM). The functions for strings are very different for other other objects such as numbers.  You need to keep track if an object type is a string or not. For example:

S = 'Hello'

S.upper()  # This will not work for a numeric type.

print(S)

[output] HELLO

Sample Code

This sample code goes through more detail of the syntax and other functions used for the various object types.  Go through it carefully and try modifying the code to see what happens. You can get the code from:

References

Here are some Python cheat sheets:

What is it?

Lists can hold different types of data and are ordered and mutable.  They can be arrays of information.

Basic Syntax

In order to create a list you need to used square brackets [] with commas in between the elements.  For example: 

L1 = [1, 2, 3, 4]              # Lists use square brackets with commas between entries.

L2 = [3.14, 'pi', True]        # Entries do not have to be the same type.

L3 = [[1, 2, 3],               # A nested list—creates a matrix‑like structure.
      [4, 5, 6],
      [7, 8, 9]]

Why it Matters?

Lists let you put a lot of information into one variable and analyze it all at once. For example:

L = [1, 2, 3, 4]

L*10

[output] [10,20,30,40]  # All the data changes at the same time.

Sample Code

This sample code goes through more detail of the syntax and other functions used for the various object types.  Go through it carefully and try modifying the code to see what happens. You can get the code from:

References

Here are some Python cheat sheets:

What is it?

Dictionaries are objects that allow to look up data.  This works by having keys connected to values.  This is one way to organize data and look it up quickly.

Basic Syntax

In order to create a dictionary type, you need to use {}.  For example: 

D = {'fruit': 'apple', 'quantity': 3, 'color': 'red'}  # Curly brackets enclose the dictionary.

# The key comes first, then a colon, and then a value.

D['fruit']

[output] apple

Why it Matters?

Dictionaries help organize structured data so that it can be more readable.  Additionally, analyzing data can be faster.

Sample Code

This sample code goes through more detail of the syntax and other functions used for the various object types.  Go through it carefully and try modifying the code to see what happens. You can get the code from:

References

Here are some Python cheat sheets:

What is it?

Tuple is an immutable collection of objects.

Basic Syntax

In order to create a tuple type, you use parentheses.  For example: 

T1 = (1, 2, 3)

T2 = (3.14, 'pi', True)

Why it Matters?

Tuples are for creating data that you don't want to change and to create keys in dictionaries. 

Sample Code

This sample code goes through more detail of the syntax and other functions used for the various object types.  Go through it carefully and try modifying the code to see what happens. You can get the code from:

References

Here are some Python cheat sheets: