Welcome @name to Python Safari - the most exciting expedition in the world of programming! I'm Darwin, your guide on this fascinating journey through the Technology Jungle.
Before you lies an unexplored jungle full of mysteries, where Python is the language of nature, and AI creatures are wild, powerful beings waiting to be tamed. In this expedition:
Python is a programming language created in 1991 by Guido van Rossum. The name comes from... well, from a python! But not the snake - from the British comedy show "Monty Python's Flying Circus". How perfectly it fits our Safari!
Imagine you're going on an expedition. You can take:
Python is the explorer's universal tool:
1# Python is readable like natural language
2temperature = 30
3if temperature > 25:
4 print("It's hot in the jungle!")The greatest discoveries in AI:
Before we head into the jungle, we need to prepare our equipment. Here's how to install Python:
1# Use Homebrew (if you don't have it, install from brew.sh)
2brew install python@3.121# Ubuntu/Debian
2sudo apt update
3sudo apt install python3.12
4
5# Fedora
6sudo dnf install python3.12Open a terminal/command prompt and type:
1python --version
2# or
3python3 --versionYou should see: `Python 3.12.X` or a newer version.
Python has a built-in interactive mode - like binoculars that let you quickly "see" the results of your code.
Type in the terminal:
1python
2# or
3python3You'll see:
1Python 3.12.0 (main, Oct 2 2023, 12:00:00)
2[Clang 15.0.0 (clang-1500.0.40.1)] on darwin
3Type "help", "copyright", "credits" or "license" for more information.
4>>>The `>>>` symbol is the prompt - Python is waiting for your commands!
Try it out:
1>>> print("Welcome to the Safari!")
2Welcome to the Safari!
3
4>>> 2 + 2
54
6
7>>> "Python" + " Safari"
8'Python Safari'
9
10>>> exit() # Exit interactive modeLet's create our first real program. Open a text editor (VS Code, PyCharm, Notepad++) and create a file called `hello_safari.py`:
1# My first Python Safari program!
2print("🌴 Welcome to the Python Jungle!")
3print("I'm ready for the expedition!")Run it in the terminal:
1python hello_safari.pyOutput:
1🌴 Welcome to the Python Jungle!
2I'm ready for the expedition!Congratulations! You've just created your first Python program! 🎉
On every expedition, a researcher takes notes. In Python, we use comments:
1# This is a comment - Python ignores it
2# It's used for explanations for humans, not for the computer
3
4print("This will execute") # A comment can be at the end of a line
5
6"""
7This is a multi-line comment
8(docstring)
9Used for documentation
10"""Python uses indentation to define code blocks (other languages use curly braces):
1# ✅ Correct
2if True:
3 print("This is indented")
4 print("This too")
5
6# ❌ Wrong - indentation error!
7if True:
8print("No indentation")1name = "Python"
2Name = "Java"
3NAME = "C++"
4
5# These are THREE DIFFERENT variables!1# Snake case for variables and functions (recommended in Python)
2my_variable = 10
3calculate_distance = lambda x: x * 2
4
5# CamelCase for classes
6class JungleAnimal:
7 passThe `print()` function displays information:
1# Simple display
2print("Text")
3print(123)
4print(3.14)
5
6# Multiple arguments
7print("Temperature:", 30, "degrees")
8
9# Separator
10print("A", "B", "C", sep="-") # A-B-C
11
12# End character (default is newline)
13print("Line 1", end=" ")
14print("Line 2") # Line 1 Line 2
15
16# F-strings (Python 3.6+) - the best way!
17name = "Darwin"
18temperature = 30
19print(f"Hello {name}, temperature: {temperature}°C")Before moving on, make sure you understand:
What is Python?
How do you run Python code?
Does Python distinguish between uppercase and lowercase?
What is indentation?
Before moving to the next lesson, make sure that:
In the next lesson we'll discover:
Darwin is waiting for you at the next camp! Good luck, brave explorer! 🐍🌴