Python Basics
Python Basics is the foundation of Python programming. In this module, you will learn how Python stores data, performs operations, works with text, and communicates with the user.
What You Will Learn
- Variables
- Data Types
- Type Conversion
- Operators
- Strings
- Input & Output
Basic Python Programming Flow
Variables & Data Types
Operators & Type Conversion
Strings
Input & Output
1. Variables
A variable is a name used to store a value in a Python program. Python automatically determines the type of value stored in the variable.
name = "Samadhan"
age = 25
print(name)
print(age)
Output:
Samadhan
25
2. Data Types
Data types define the kind of value stored in a variable. Python provides several built-in data types.
| Data Type | Example |
|---|---|
| int | 25 |
| float | 25.50 |
| str | "Python" |
| bool | True |
3. Type Conversion
Type conversion means changing a value from one data type to another data type.
age = "25"
age = int(age)
print(age)
print(type(age))
Output:
25
<class 'int'>
4. Operators
Operators are symbols used to perform operations on values and variables.
a = 10
b = 5
print(a + b)
print(a - b)
print(a * b)
print(a / b)
Output:
15
5
50
2.0
5. Strings
A string is a sequence of characters. Strings are commonly used to store names, messages, addresses, and other text data.
name = "Samadhan"
print(name)
print(name.upper())
Output:
Samadhan
SAMADHAN
6. Input & Output
Python provides the input() function to receive data from the user.
name = input("Enter your name: ")
print("Welcome", name)
Example Output
Enter your name: Samadhan
Welcome Samadhan
Example 🌍🫥
Suppose we want to store information about a student at CIIT Training Institute.
student_name = "Samadhan"
course = "Python Programming"
experience = 0
print("Student:", student_name)
print("Course:", course)
print("Experience:", experience)
Output:
Student: Samadhan
Course: Python Programming
Experience: 0
CIIT Learning Point
Before learning advanced Python concepts, make sure you are comfortable with variables, data types, type conversion, operators, strings, and user input. These concepts will be used throughout your Python development journey.
CIIT Practice Task
Create a Python program that accepts a student's name and course and displays the information.
name = input("Enter student name: ")
course = input("Enter course name: ")
print("Student:", name)
print("Course:", course)
Output:
Enter student name: Samadhan
Enter course name: Python Programming
Student: Samadhan
Course: Python Programming
Summary :
Python Basics introduces the core concepts required for programming with Python. You learned about variables, data types, type conversion, operators, strings, and input and output. These concepts form the foundation for writing practical Python programs.