Getting Started with Python

· 3 min read · Updated March 7, 2026 · beginner
getting-started print strings numbers scripts

Your First Python Script

Create a file called hello.py using any text editor. Add the following line:

print("Hello, world!")

Save the file and run it from your terminal:

python3 hello.py

Output:

Hello, world!

That single line is a complete Python program. No boilerplate, no imports, no class definitions — just a direct instruction to print text to the screen.

Using the REPL for Quick Experiments

The REPL lets you run Python code one line at a time. Start it with:

python3

Then type expressions directly:

>>> print("Hello from the REPL")
Hello from the REPL
>>> 10 * 5
50
>>> type(3.14)
<class 'float'>

The REPL is ideal for testing ideas before putting them into a script. Use exit() to quit.

The print() Function

print() sends output to the terminal. It accepts one or more arguments, separated by commas:

print("Python", "is", "fun")

Output:

Python is fun

By default, print() separates arguments with a space and ends with a newline. You can change both behaviors:

print("one", "two", "three", sep="-")
# one-two-three

print("loading", end="...")
print("done")
# loading...done

Comments

Comments explain your code to other humans (and to your future self). Python ignores everything after a # on a line:

# This is a comment on its own line
name = "Alice"  # This is an inline comment

# Comments are useful for:
# - explaining WHY something is done
# - temporarily disabling code
# - leaving notes for collaborators

Python has no dedicated multi-line comment syntax. For multiple comment lines, use consecutive # markers. Triple-quoted strings ("""...""") are sometimes used for multi-line notes, but they are technically string literals, not comments.

Strings

Strings are sequences of characters, enclosed in single or double quotes:

greeting = "Hello"
language = 'Python'

# Both are identical in behavior. Pick one style and stay consistent.
print(greeting)   # Hello
print(language)   # Python

Use triple quotes for strings that span multiple lines:

message = """This string
spans multiple
lines."""
print(message)

Common string operations:

text = "python"

print(text.upper())       # PYTHON
print(text.capitalize())  # Python
print(len(text))          # 6
print(text[0])            # p  (indexing starts at 0)
print(text.replace("py", "Cy"))  # Cython

Numbers

Python has two main number types: integers (int) and floating-point numbers (float).

count = 42          # int
price = 19.99       # float
negative = -7       # int
scientific = 3e8    # float (300000000.0)

Basic arithmetic works as expected:

print(10 + 3)    # 13    addition
print(10 - 3)    # 7     subtraction
print(10 * 3)    # 30    multiplication
print(10 / 3)    # 3.333...  division (always returns float)
print(10 // 3)   # 3     floor division (rounds down)
print(10 % 3)    # 1     modulo (remainder)
print(10 ** 3)   # 1000  exponentiation

Division with / always produces a float, even when the result is a whole number (10 / 2 returns 5.0). Use // when you need an integer result.

Mixing Strings and Numbers

You cannot concatenate a string and a number directly:

age = 25
# print("I am " + age + " years old")  # TypeError!

Convert the number to a string first with str(), or use an f-string:

age = 25
print("I am " + str(age) + " years old")
print(f"I am {age} years old")  # f-string (cleaner)

F-strings (formatted string literals, prefixed with f) are the modern, preferred approach. They evaluate expressions inside curly braces at runtime.

Creating and Running .py Files

A few practical tips for working with script files:

# save this as greet.py
name = "World"
year = 2026
print(f"Hello, {name}! Welcome to {year}.")

Run it:

python3 greet.py
# Hello, World! Welcome to 2026.

Keep your filenames lowercase, use underscores instead of spaces (my_script.py, not My Script.py), and always use the .py extension so editors and tools recognize the file as Python.

Next Steps

You now know how to create scripts, use print(), write comments, and work with strings and numbers. Next up: variables, types, and operators.