Conquering the Python Jungle: The First Step into the Coding verse.

akki
𝐀𝐈 𝐦𝐨𝐧𝐤𝐬.𝐢𝐨
5 min readMay 8, 2024

Welcome back, AI adventurers! Today, we’re taking our first steps into the vibrant jungle of Python, the essential tool for building your AI arsenal.

Why Python?

Python is a pretty popular programming language which was created by Guido van Rossum, and released in 1991. It might seem like just another snake in the code zoo, but trust me, it’s a friendly one! Unlike some programming languages that can feel like cryptic puzzles, Python boasts a clear and concise syntax, making it remarkably easy to learn and read. Imagine writing instructions in plain English — that’s the beauty of Python!

Note: The most recent major version of Python is Python 3.

Building Blocks: Variables and Data Types

Every journey begins with a single step, and in Python, that step involves understanding variables and data types. Think of variables as little boxes where you can store information you want to use later in your code. Just like you wouldn’t put a book in a shoebox, Python uses different data types to store different kinds of information. We’ll explore basic data types like:

  • Numbers (Integers and Decimals): These represent numerical values. Integers (whole numbers) can be positive, negative, or zero, written like 10, -5, or 0. Decimals (numbers with a decimal point) are written like 3.14 or -2.5.
# Example: Assigning different number values to variables
age = 25
pi = 3.14159

print("My age is", age)
# Output: My age is 25

print("The value of pi is", pi)
# Output: The value of pi is 3.14159

The print() function takes anything you put between the parentheses and prints it to the screen. But we must feed it the correct type of data for it to work. Quotes around strings are essential because they precisely mark the start and end of a string. This way, a string is easy to recognize for Python.

‘#’ is used for commenting in code. Comments can be used to explain Python code. It also makes the code more readable.

  • Text (Strings): These represent sequences of characters and are written within single or double quotes.
# Example: Assigning text to a variable
name = "Alice"

print("Hello,", name)
# Output: Hello, Alice
  • Logical Values (True or False): These represent Boolean values and are used to indicate true or false conditions.
# Example: Checking if a number is even
number = 10
is_even = number % 2 == 0
# The modulo operator (%) checks for remainder.
# Even numbers have no remainder when divided by 2.

print("The number", number, "is even:", is_even)
# Output: The number 10 is even: True

Operators: Your Programming Tools

Now that you have your data stored in variables, it’s time to manipulate it! Operators are the tools in your Python toolbox that allow you to perform calculations, comparisons, and other essential tasks. We’ll conquer basic operators like:

  • Arithmetic Operators: These perform mathematical calculations.
# Example: Performing basic arithmetic operations
a = 5
b = 7
addition = a + b
subtraction = a - b
product = a * b

print("The sum of 5 and 7 is:", addition)
# Output: The sum of 5 and 7 is: 12

print("The difference between 5 and 7 is:", subtraction)
# Output: The difference between 5 and 7 is: -2

print("The product of 5 and 7 is:", product)
# Output: The product of 5 and 7 is: 35
  • Comparison Operators: These compare values and return True or False.
# Example: Comparing numbers
age1 = 30
age2 = 25

is_older = age1 > age2

print("Is", age1, "older than", age2, "?", is_older)
# Output: Is 30 older than 25 ? True

Putting it all Together: Your First Python Program

Enough theory, let’s get coding! Let’s write our very first Python program together. Here’s a simple program that greets you by name:

# Your first Python program!

name = input("What is your name? ")
# Get user input using the input() function

print("Hello,", name, "!")
# Personalized greeting

How to run the code:

  1. Open a notepad, type out your code and save it as hello_world.py (a .py file is a Python source code file)

2. Open command prompt and browse to your saved location. (I would suggest googling how to access directory in command promt if it’s your first time using it)

3. Once you are in the directory or location where you have saved your hello_world.py file, run the program by typing ‘python hello_world.py’ and press enter. When prompted, enter your name, and the program will greet you!

Congratulations on successfully running your very first python program!

The Adventure Continues…

This is just the tip of the Python iceberg, but with these foundational blocks in place, you’re well on your way to building more complex programs.

Now, that you have started, do not stop! I would suggest a really good free tutorial for beginners by freecodecamp on YouTube! What makes it stand out from other tutorials on YouTube is the fact that they have associated mini-projects along the way that will help you understand the key features of Python. They have organised it as a video textbook with 23 chapters for you to learn. Unlike how we used a notepad here for our programming purposes, you will learn to use VS Code, a pretty useful and feature rich code editor.

In the upcoming post, we’ll delve deeper into the following:

  • Control Flow Statements: These statements control the flow of execution in your program. We’ll explore concepts like if statements for making decisions and loops (like for and while) for repetitive tasks. (covered by the suggested video above)
  • Functions: Imagine reusable blocks of code — that’s what functions are! We’ll learn how to define functions to modularize your code and make it more efficient. (covered by the suggested video above)
  • Data Structures: Just like you wouldn’t throw all your supplies in a single backpack on an adventure, Python offers organized ways to store data. We’ll explore lists (ordered collections of items) and dictionaries (collections of key-value pairs) for better data management. (covered by the suggested video above)

Ready to embark on the next leg of your coding adventure? Stay tuned for the next post! In the meantime, feel free to share your experiences in the comments below.

P.S. I only suggest resources that I have myself consumed and learned from. So kindly be rest assured and keep learning!!!

--

--