Python Foundations: Writing Simple Scripts & Mastering Basic Data Types

Step 1: What is Coding? Getting Oriented

Objective: Understand what programming is and what Python can be used for.

Programming is giving instructions to your computer to solve problems or perform tasks. Python is a widely used, beginner-friendly language suitable for many purposes like data analysis, automation, and creating web applications.


# This is a Python comment.
print("Hello, Python!")
content_copy

Step 2: Setting Up Your Tools

Objective: Install Python and choose a text editor.

Head to python.org and download the latest version of Python for your operating system. A text editor lets you write code—try Visual Studio Code, Atom, or even Notepad++. The terminal or command prompt helps you run your code files.


# Save this as hello.py
print("Setup complete!")
content_copy

Step 3: Running Your First Python Script

Objective: Create and run your first Python program.

Write a simple Python file in your editor and save it as hello.py. Open your terminal, navigate to the file’s location, and run it:


# hello.py
print("Congratulations! You ran your first Python script.")
content_copy

To run: python hello.py

Step 4: Introduction to Variables

Objective: Understand and use variables to store data in Python.

In Python, you assign a value to a variable using the = sign. Variable names should be descriptive so you remember what they store.


name = "Sam"
age = 24
print("Name:", name)
print("Age:", age)
content_copy

Step 5: Working with Numbers

Objective: Learn how to use numbers and do basic math in Python.

Doing calculations in Python is easy. Use +, -, *, and / for math.


a = 10
b = 3
print(a + b)
print(a - b)
print(a * b)
print(a / b)
content_copy

Step 6: Strings: Working with Text

Objective: Understand and use strings to store and manipulate text.

A string in Python is text inside quotes. You can combine (concatenate) strings, or find out their length.


greeting = "Hello"
name = "Sam"
message = greeting + ", " + name + "!"
print(message)
print("Length:", len(message))
content_copy

Step 7: Lists: Organizing Multiple Items

Objective: Store and access multiple values efficiently using lists.

Lists can store numbers, strings, or any mix. Each item is numbered starting from zero.


groceries = ["apples", "bread", "milk"]
print(groceries[0])
groceries.append("eggs")
print(groceries)
content_copy

Step 8: Dictionaries: Key-Value Pairs

Objective: Use dictionaries to associate keys with values.

Think of a dictionary as a set of name-value pairs. For example, you might keep track of someone’s contact info.


phonebook = {"Alice": "555-1234", "Bob": "555-5678"}
print(phonebook["Alice"])
phonebook["Eve"] = "555-9999"
print(phonebook)
content_copy

Step 9: Making Choices: if Statements

Objective: Write code that makes decisions using if, elif, and else.

The if statement lets your code do different things based on logic. Use elif and else for alternatives.


age = 17
if age < 18:
    print("Minor")
elif age == 18:
    print("Just became an adult!")
else:
    print("Adult")
content_copy

Step 10: Repeating with Loops

Objective: Use for and while loops to automate repetitive tasks.

A for loop works with lists. A while loop repeats as long as a condition is true.


# For loop
for i in range(3):
    print("Hello!", i)

# While loop
count = 0
while count < 3:
    print("Counting:", count)
    count += 1
content_copy

Step 11: Getting User Input

Objective: Ask for and use input from the user during program execution.

Use input() to get data from the person running your script. Always convert input to the type you need!


name = input("What's your name? ")
age = input("How old are you? ")
print("Hello,", name)
print("You are", age, "years old.")
content_copy

Step 12: Summary and Next Steps

Objective: Review what you’ve learned and explore where to go next.

You’ve learned to write Python scripts, manage data using variables and basic types, make decisions, and loop actions. Keep practicing with small projects—like calculators or text games—and review each concept to strengthen your skills.

Next steps: Try learning about functions (to organize your code), working with files for reading/writing data, and tackling simple projects. As you grow, consider exploring Python’s modules and libraries for data, websites, or automation!