Practical Coding in Python

Learn to write and validate your own code

Darren Kessner, PhD

(revised September 1, 2025)

Previous: Hello

Basics

#
# basics.py
#

# Comments are specified by the octothorpe (hashtag) `#`. 

# You declare a variable by assigning it.

# In Python, the variable's type is dynamic: both the type and
# value of a variable can change.  All types are reference types:
# every variable refers to an object, but the class can change.
# The basic types in Python are similar to the wrapper types
# Integer, Float, etc. in Java.

x = 5       # integer
print("x:", x)

x = 1.23    # float
print("x:", x)

x = "hello" # string
print("x:", x)

x = True    # boolean
print("x:", x)

Output:

x: 5
x: 1.23
x: hello
x: True

Next: