Logo

CHiPSET

A Technical Community

Python Fundamentals: Variables, Data Types and Input/Output

Start learning Python programming with simple beginner-friendly examples. This article explains Python basics including variables, data types, comments, user input, type conversion, step by step. This is episode 2 of python for aiml stay tuned for learning

ChakradharMay 13, 202635 min
#python#input and output
Python Fundamentals: Variables, Data Types and Input/Output

Python for AI/ML – Episode 2

Understanding Python Basics for Artificial Intelligence and Machine Learning

In the previous episode, we successfully installed Python and set up the development environment required for Artificial Intelligence and Machine Learning projects. Now, in Episode 2, we will begin learning the fundamentals of Python programming that form the backbone of AI and ML development.

Python is one of the most popular programming languages in the world because of its simple syntax, readability, and massive collection of libraries. Most AI and ML frameworks such as TensorFlow, PyTorch, Scikit-learn, and Pandas are built using Python. Therefore, understanding Python basics is the first step toward becoming an AI/ML developer.

Why Python for AI and ML?

Python is widely used in AI and ML because:

  • It is easy to learn and beginner-friendly.
  • It has simple and readable syntax.
  • It provides powerful libraries for data analysis and machine learning.
  • It supports automation and rapid development.
  • It has a huge community and excellent documentation.
  • Due to these advantages, companies and researchers prefer Python for building intelligent systems.

    Writing Your First Python Program

    The first program most beginners write is the “Hello World” program.

    print("Hello World")

    Image

    Image

    Printing in Python

    Printing means displaying output on the screen. Python uses the print() function to show messages, values, and results.

    Syntax of print()

    print("Hello")

    Printing Text

    Text must be written inside quotes.

    Example

    print("Hello World")

    Output

    Hello World

    Printing Numbers

    Numbers can be printed without quotes.

    Image

    Image

    image showing printing numbers in python

    Variables in Python

    Think of a variable as a labeled storage box. In Python, you use these boxes to store data so you can refer to it later by name.

    Unlike some other languages, Python is "dynamically typed," which means you don’t have to tell the computer what kind of data is going inside the box ahead of time. You just give it a name and assign a value.

    1. The Anatomy of a Variable

    To create a variable, you follow a simple pattern: name = value.

    Image

    Image

    image showing variable types

    Variable Properties

    1. Variable Name Rules

    A variable name:

  • Can contain letters, numbers, and underscores
  • Cannot start with a number
  • Cannot contain spaces
  • Correct

    Image

    Image

    Wrong

    1name = "Alex"student name = "Alex"

    2. Case-Sensitive

    Python treats uppercase and lowercase differently.

    age = 20

    Age = 30

    Here:

  • age and Age are two different variables.
  • 3. No Reserved Keywords

    Python keywords cannot be used as variable names.

    Wrong

    class = 10for = 5

    Because:

  • class
  • for
  • if
  • while
  • are already used by Python.

    4. No Spaces

    Variable names cannot contain spaces.

    Wrong

    student name = "Chipset"

    Correct

    student_name = "Chipset"

    Underscores _ are used instead of spaces.

    5. Dynamic Typing

    Python automatically decides the type of variable.

    x = 10x = "Python"

    First:

  • x is an integer
  • Later:

  • x becomes a string
  • Python allows changing data types dynamically.

    6. Memory Allocation

    When a value is assigned to a variable, Python stores it in memory.

    name = "AI"

    Here:

  • Memory is allocated to store "AI".
  • 2. Basic Data Types

    Variables can hold different "flavors" of data. Here are the most common ones you'll use:

    Image

    Image

    an image on data types and their properties in python

    1. Integer (int)

    Integers are whole numbers.

    x = 10

    Properties

  • No decimal point
  • Can be positive or negative
  • Immutable (cannot be modified directly)
  • Examples

    a = 100b = -25

    2. Float (float)

    Floats are decimal numbers.

    pi = 3.14

    Properties

  • Contains decimal values
  • Used in calculations
  • Immutable
  • Examples

    height = 5.8temperature = 36.5

    3. String (str)

    Strings store text.

    name = "Danesh"

    Properties

  • Written inside quotes
  • Stores characters and text
  • Immutable
  • Examples

    city = "Chennai"

    course = "Python"

    4. Boolean (bool)

    Booleans represent logical values.

    is_active = True

    Properties

  • Only two values:
  • True
  • False
  • Used in conditions and decision-making
  • Examples

    is_logged_in = False

    whatever we saw till now are primitive data types we will explore further on other data types in coming episodes

    Checking Data Types

    We can check the type using type().

    Example

    Image

    Image

    image showing o/p on type() function

    Comments in Python

    Comments are notes written inside a program to explain the code. Python ignores comments during execution.

    Comments help to:

  • Improve readability
  • Explain code logic
  • Make programs easier to understand
  • Types of Comments in Python

  • 149Single-Line Comments
  • 150Multi-Line Comments
  • Single-Line Comments

    Single-line comments start with #.

    Syntax

    # This is a comment

    Image

    Image

    this image shows how the program ignores comment lines and prints output

    Multi-Line Comments

    Triple quotes are commonly used for multi-line comments.

    Syntax

    """This is a multi-line comment"""

    Image

    Image

    example showing multi-line comments

    Printing Variables

    As seen Above variables can printed very easily in python

    Image

    Image

    image depicting printing variables

    Printing Multiple Values

    Multiple values can be printed using commas.

    Image

    Image

    Using Separator (sep)

    The sep parameter changes the separator between values.

    Image

    Image

    Image showing usage of sep

    Using End (end)

    The end parameter changes the ending character.

    Image

    Image

    Overall printing functions are shown below

    Image

    Image

    Input in Python

    Input means taking data from the user while the program is running. In Python, the input() function is used to receive values from the keyboard.

    This makes programs interactive because the user can give different values every time the program runs.

    Syntax:

    input("Message")

    The text inside quotes is shown to the user. Whatever the user types is returned by the input() function.

    Basic Input Example

    Image

    Image

    Output

    Enter your name: chipset

    chipset

    Explanation

  • input() asks the user to enter a value.
  • The entered value is stored in the variable name.
  • print(name) displays the stored value.
  • Input with a Message

    Usually, we display a message so the user understands what to enter.

    Image

    Image

    Important Point About input()

    By default, Python stores all input values as strings (str).

    Even if the user enters a number, Python treats it as text.

    Image

    Image

    image showing default input type

    Why Type Conversion is Needed

    Suppose we take two numbers as input:

    a = input("Enter first number: ")

    b = input("Enter second number: ")

    print(a + b)

    Output

    1020

    Explanation

    Python joins the strings instead of adding them mathematically.

  • "10" + "20" becomes "1020"
  • So, we need type conversion.

    Integer Input using int()

    The int() function converts input into an integer.

    Image

    Image

    image showing integer input

    Explanation

  • input() receives the value
  • int() converts it into a number
  • Python performs mathematical addition
  • Float Input using float()

    The float() function converts input into decimal numbers.

    Example

    height = float(input("Enter height: "))

    print(height)

    Output

    Enter height: 5.85.8

    Taking Multiple Inputs

    We can take multiple values from the user.

    Example

    name = input("Enter name: ")

    age = int(input("Enter age: "))

    print(name, age)

    Output

    Enter name: chipset

    Enter age: 19

    chipset 19

    Real-Life Uses of Input

    Input is used in:

  • Login systems
  • Registration forms
  • AI chatbots
  • Online calculators
  • Games
  • Machine learning applications
  • Almost every interactive application uses input functions.

    Homework

    Try these programs on your own to improve your understanding of Python basics:

  • 263Write a program to print your:
  • Name
  • Age
  • Favorite programming language
  • 267Create variables to store:
  • Your name
  • College name
  • Department
  • CGPA Then print all the values.
  • Conclusion

    In this article, we learned the basic fundamentals of Python programming, including:

  • Printing statements using print()
  • Taking user input using input()
  • Variables and variable naming rules
  • Basic data types like int, float, bool, and str
  • Comments in Python
  • These concepts form the foundation of Python programming and are essential for Artificial Intelligence and Machine Learning development.

    Keep practicing these basics regularly, because strong fundamentals make advanced programming much easier to learn.

    Stay tuned for the next episode to explore more Python concepts and continue your journey into AI and Machine Learning.

    Tags:#python#input and output

    Written by Chakradhar on May 13, 2026