Introduction to Python Programming

What is Python?

Python is a versatile, high-level programming language known for its simplicity and readability. It supports various programming paradigms, making it suitable for diverse applications, including web development, data analysis, artificial intelligence, and automation.

1. Variables and Data Types

In Python, variables are used to store and manipulate data. Variables do not require explicit declarations; you simply assign a value to them.

# Integer variable
age = 25

# Floating-point variable
height = 1.75

# String variable
name = "John Doe"

2. Declaration and Assignment

  • Declaration: You don't need to declare the data type explicitly. Python infers it based on the assigned value.
  • Assignment: Use the = operator to assign a value to a variable.
# Integer declaration and assignment
num_of_students = 100

# Floating-point declaration and assignment
pi_value = 3.14

# String declaration and assignment
greeting_message = "Hello, Python!"

3. Data Types in Python

Python supports various data types, including:

  • int: Integer (whole numbers)
  • float: Floating-point (decimal numbers)
  • str: String (text)

4. Printing Values

The print() function is used to display values. You can print variables or direct values.

# Printing integer value
print(num_of_students)

# Printing floating-point value
print(pi_value)

# Printing string value
print(greeting_message)

5. Operations with Variables

You can perform mathematical operations on numeric variables.

# Mathematical operations
result = num_of_students * 2
print(result)

# Combining strings
full_name = name + " Smith"
print(full_name)

These fundamental concepts form the basis of Python programming. As you progress, you'll explore more advanced topics and gain the skills to build complex applications.