Sitemap

Python Variables, Data Types, Operators, Input & Output

5 min readSep 24, 2026

--

Press enter or click to view image in full size

Day 2 of my Generative AI Learning Journey

In my previous article, I started my Generative AI learning journey with Python and discussed why Python is important for AI, Machine Learning, and Gen AI.

Today, I’m revisiting some of the most fundamental Python concepts:

  • Variables
  • Data types
  • Operators
  • Input
  • Output
  • Type conversion

These concepts may look simple, but they are used constantly when building Python applications, including AI and Gen AI applications.

1. Variables in Python

A variable is a name used to store a value.

For example:

name = "Gen AI"
age = 21
experience = 0

Here:

  • name stores a string
  • age stores an integer
  • experience stores an integer

We can access these values using their variable names:

print(name)
print(age)
print(experience)

Output:

Gen AI
21
0

Python doesn’t require us to explicitly declare the data type of a variable.

For example:

name = "Python"
age = 25
price = 99.99

Python automatically determines the type based on the value assigned.

2. Data Types in Python

A data type tells us what kind of value a variable contains.

Some commonly used Python data types are:

Data TypeExampleint10float10.5str"Python"boolTruelist[1, 2, 3]tuple(1, 2, 3)set{1, 2, 3}dict{"name": "Python"}NoneTypeNone

Let’s look at a few examples.

Integer

age = 21

Float

price = 99.99

String

language = "Python"

Boolean

is_learning = True

We can check the type using type():

age = 21
print(type(age))

Output:

<class 'int'>

3. Strings

Strings are used to represent text.

name = "Generative AI"

We can perform different operations on strings.

first_name = "Gen"
last_name = "AI"
full_name = first_name + " " + last_nameprint(full_name)

Output:

Gen AI

Strings are particularly important in Gen AI because much of the information we work with is text.

For example:

prompt = "Explain machine learning in simple words."

Here, the prompt is stored as a Python string.

This is one of the simplest connections between basic Python and Gen AI.

4. Boolean Data Type

A Boolean has only two possible values:

True
False

For example:

is_model_available = True
is_training_complete = False

Boolean values are frequently used in conditions and program logic.

5. Operators in Python

Operators are symbols used to perform operations on values.

Python provides several types of operators.

Arithmetic Operators

These are used for mathematical calculations.

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

Some common arithmetic operators are:

OperatorMeaning+Addition-Subtraction*Multiplication/Division%Modulus**Exponentiation//Floor division

6. Comparison Operators

Comparison operators compare two values.

a = 10
b = 20
print(a == b)
print(a != b)
print(a > b)
print(a < b)

Output:

False
True
False
True

Common comparison operators include:

==    Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

These become useful when writing conditions and controlling program behavior.

7. Logical Operators

Logical operators are used to combine conditions.

Get SONALI BALLA’s stories in your inbox

Join Medium for free to get updates from this writer.

Python provides:

and
or
not

Example:

age = 22
has_skill = True
print(age > 18 and has_skill)

Output:

True

These operators become useful when building more complex program logic.

8. Taking Input From the User

Python provides the input() function to take input from the user.

name = input("Enter your name: ")
print("Hello", name)

If the user enters:

Sonali

The output will be:

Hello Sonali

One important thing to remember is that input() returns a string by default.

For example:

age = input("Enter your age: ")
print(type(age))

Even if the user enters:

21

the type will be:

<class 'str'>

9. Type Conversion

Sometimes we need to convert one data type into another.

For example:

age = input("Enter your age: ")
age = int(age)print(type(age))

Now age becomes an integer.

Some common conversion functions are:

int()
float()
str()
bool()

Example:

number = "100"
number = int(number)print(number + 50)

Output:

150

10. Output Using print()

The print() function is used to display information.

name = "Python"
print(name)

We can also print multiple values:

language = "Python"
year = 2026
print(language, year)

11. Formatted Strings — f-Strings

One useful feature of Python is the f-string.

name = "Python"
version = 3.14
print(f"I am learning {name} {version}")

Output:

I am learning Python 3.14

f-strings are useful when we need to combine text and variables.

For example, when working with AI applications, we might construct dynamic prompts:

topic = "Generative AI"
prompt = f"Explain {topic} in simple terms."print(prompt)

Output:

Explain Generative AI in simple terms.

This is a simple example, but the same idea of dynamically creating strings can appear in larger AI applications.

12. A Small Python Practice Program

Let’s combine what we learned.

name = input("Enter your name: ")
age = int(input("Enter your age: "))
topic = input("What are you learning? ")
print(f"\nHello {name}!")
print(f"You are {age} years old.")
print(f"You are currently learning {topic}.")

This small program uses:

  • Variables
  • Strings
  • Integers
  • Input
  • Type conversion
  • Output
  • f-strings

How These Concepts Connect to Gen AI

At first, variables, strings, operators, and input/output may seem unrelated to Generative AI.

But they form the foundation of the applications we’ll build later.

For example, consider a simple AI application:

user_question = input("Ask a question: ")
prompt = f"Answer this question clearly: {user_question}"response = model.generate(prompt)print(response)

The AI model is doing the sophisticated part, but the surrounding application still uses basic Python concepts:

User Input
↓
Python Variable
↓
String / Prompt
↓
AI Model
↓
Response
↓
Python Output

This is why I’m revisiting the fundamentals instead of skipping directly to Gen AI frameworks.

What I Learned Today

Today’s concepts were:

> Variables
> Python data types
> Strings
> Boolean values
> Arithmetic operators
> Comparison operators
> Logical operators
> Input and output
> Type conversion
> f-strings

The most important takeaway for me is that simple Python concepts become building blocks for much larger AI applications.

I don’t need to memorize every Python feature before moving forward. What matters is understanding the fundamentals and knowing how to apply them.

What’s Next?

In the next article, I’ll explore:

Day 3: Conditional Statements and Loops in Python

I’ll learn how Python makes decisions and repeats tasks — two fundamental concepts that are used in almost every programming application.

One step at a time. One concept at a time.

#Python #GenerativeAI #GenAI #ArtificialIntelligence #MachineLearning #PythonProgramming #LearningInPublic

--

--

SONALI BALLA
SONALI BALLA

Aspiring Gen AI Engineer | Learning, building, and sharing my Generative AI journey.