Day 2: Variables, Data Types, and Math—Start Coding Now!

Python Day 2: Getting Hands-On with Your First Code!

Welcome back, future Pythonista! Yesterday, we established that Python is your golden ticket into Data Science, Web Development, and AI, all thanks to its simple, English-like syntax. Today, we put that theory into practice. Day 2 is all about diving into the Absolute Basics and writing your very first functional code.


1. The Simplest Start: Variables and Data Types

In Python, a variable is just a container that holds information. Think of it like labeling a box. You pick a name (the variable), and you put something inside (the data).

The best part? Python is dynamically typed, meaning you don't have to declare what kind of data is going into the box—it figures that out automatically!

Here are the four essential 'boxes' (Data Types) you need to know:

Type What it is Example
String (str) Text or characters "Hello, world!", "Python Day 2"
Integer (int) Whole numbers 10, 500, -3
Float (float) Numbers with a decimal point 3.14, 0.5, 100.0
Boolean (bool) True or False values True, False

Your First Code: Creating Variables

In your editor or a free online Python interpreter (like Google Colab), try typing this:

# Create variables
name = "Alex"
age = 28
height_meters = 1.75
is_learning = True

# Display the data
print(name)
print(age)

What you just did: You created four variables and used the simple print() function (a pre-built command) to display two of them. You're already coding!


2. Basic Math and Operators

Python can be used as a super-powerful calculator. It uses familiar arithmetic operators

Operator Action Example Result
+ Addition 5 + 3 8
- Subtraction 10 - 4 6
* Multiplication 4 * 6 24
/ Division 20 / 5 4.0
** Exponent (Power) 2 ** 3 8

Code Challenge: Calculate Your Future Salary

Let's use a variable in a calculation. Imagine you predict your starting salary is $60,000 and it will grow by $5,000 each of the next 5 years.

# The initial variable
current_salary = 60000

# The calculation (Current + (Growth * Years))
future_salary = current_salary + (5000 * 5)

print(future_salary) 
# Output: 85000

This is a small taste of how Python helps automate calculations in Data Science and Finance!


3. String Manipulation: More Than Just Text

Strings are essential for everything from generating reports to crafting web page content. Python lets you do cool things with them:

  • Concatenation (Adding Strings): Use the + sign.
  • f-Strings (The Modern Way): This allows you to easily embed variables inside a string. Just start the string with an f before the quotes.

Code Example: Building a Sentence

first_name = "Guido"
last_name = "Van Rossum" # Python's creator

# Concatenation (The Classic Way)
full_name_classic = first_name + " " + last_name
print(full_name_classic) 

# f-String (The Pythonic Way)
greeting = f"Hello, my name is {first_name} and I created Python!"
print(greeting)

The f-String approach (f"...") is incredibly powerful and will save you tons of time when you start building reports or generating dynamic web content with frameworks like Django or Flask.


Your Day 2 Homework & Career Focus

You've officially written code! Today's lesson covered the absolute cornerstones of any programming language: data storage (variables) and basic operations.

Homework:

  1. Create a variable for your dream job title and another for your favorite Python use case (e.g., "Data Analyst" and "AI").
  2. Use an f-String to print a motivational sentence about your goal.

Example: f"I am learning Python to become a {job_title} and master {use_case}!"

By the end of this journey, these simple commands will be the building blocks for complex applications. Keep your focus on those career goals—every line of code is a 30% boost to your CV!

See you for Day 3!

0 Comments

Please do not spam

Subscribe

Fill in all informations