๐Ÿ Python Training - Day 1

Introduction, Data Types, Variables, Expressions, Statements & Functions

๐Ÿ“ Quick Quiz (5 Questions)

  1. Which is a boolean value?
  2. Which has higher precedence?
  3. Select the string literal:
  4. Function definition keyword is:
  5. Lists are:
Answer all questions and click Submit.

๐Ÿ“š Introduction to Python

Python is a high-level, interpreted programming language known for its readability and versatility. It's widely used for web development, data analysis, automation, and more.

Installation Steps:

  1. Visit python.org/downloads/
  2. Download the latest version
  3. Run installer and add Python to PATH
  4. Verify: python --version

๐Ÿ”ข Basic Data Types

Integer (int)

Whole numbers without decimal points

port_count = 48

Float

Numbers with decimal points

cpu_usage = 15.75

Boolean

True or False values

is_active = True

String

Sequences of characters

hostname = "Switch01"

List

Ordered collections of items

vlans = [10, 20, 30, 40]

โšก Variables, Expressions & Statements

Variables

Store data values and are created when you assign a value to them.

ip_address = "192.168.1.1"

Expressions

Combinations of values, variables, and operators that compute a value.

total_ports = port_count + 4

Statements

Instructions that the Python interpreter can execute.

print(hostname)

Operator Precedence

  1. Parentheses ()
  2. Exponentiation **
  3. Multiplication, Division *, /, //, %
  4. Addition, Subtraction +, -
  5. Comparison ==, !=, >, <, >=, <=
  6. Logical and, or, not

๐Ÿ’ฌ Comments

Comments explain code and are ignored by the interpreter.

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

๐Ÿ”Ž Indentation in Python

Python uses indentation to define code blocks. The recommended style is 4 spaces per level. Be consistent and avoid mixing tabs and spaces to prevent IndentationError.

Correct indentation (4 spaces)

hostname = "Switch01"
port_count = 48

if port_count > 24:
    print(f"{hostname} is a high-density switch")
    for vlan in [10, 20, 30, 40]:
        print(f"Configuring VLAN {vlan}")
print("Done")

Incorrect indentation (raises IndentationError)

hostname = "Switch01"

if True:
print(hostname)  # โŒ Not indented under if

Practical snippet (well-indented)

# Examples Related to Cisco Network Topology
# Example 1: Displaying Switch Details
hostname   = "Switch01"
ip_address = "192.168.1.1"
port_count = 48
vlans      = [10, 20, 30, 40]
is_active  = True

print(f"Hostname: {hostname}")
print(f"IP Address: {ip_address}")
print(f"Port Count: {port_count}")
print(f"VLANs: {vlans}")
print(f"Is Active: {is_active}")

๐Ÿง  Midโ€‘Session Quiz

  1. Which data type is a sequence of characters?
  2. Which line creates a variable named ip?
  3. Which is an expression?
  4. Which is a proper singleโ€‘line comment in Python?
  5. Indentation per level should typically be:
Answer all questions and click Submit.

๐ŸŽฎ Interactive Demo: Data Types

Try different data types:

Click the button to see the data type of your input!

๐Ÿ”ง Functions

What is a Function?

A function is a block of code that performs a specific task. Functions help in reusability and organization of code.

Defining a Function

def greet(): print("Hello, welcome to the network management system!")

Calling a Function

greet()

Parameters and Arguments

def configure_vlan(vlan_id, vlan_name): print(f"Configuring VLAN ID: {vlan_id}, VLAN Name: {vlan_name}") configure_vlan(10, "Management")

๐Ÿ”„ Flow of Execution

The flow of execution refers to the order in which statements are executed. In Python, execution starts from the first line of the script and proceeds sequentially. When a function is called, the flow jumps to the function, executes its code, and then returns to the next line after the function call.

Example: Network Topology

def configure_vlan(switch_name, vlan_id, vlan_name): print(f"Configuring {switch_name}: VLAN {vlan_id} - {vlan_name}") def setup_network(): configure_vlan("SW101", 10, "Management") configure_vlan("SW102", 20, "Data") configure_vlan("SW110", 30, "Voice") def main(): print("Starting network setup...") setup_network() print("Network setup complete!") if __name__ == "__main__": main()

โ–ถ๏ธ Run the code (Python in your browser)

You can execute Python directly below using Pyodide. Edit the code and click Run.

Initializing Python runtime...

๐ŸŽฎ Interactive Demo: Function Practice

Create a simple function:

Enter a function and click run to see the output!

๐Ÿ“Š Quick Comparison (Recap)

Concept What Example
Variable Named storage ip = "192.168.1.1"
Expression Computes a value 48 * 1000
Statement Action to execute print(hostname)

๐Ÿ“ Quick Quiz (Recap)

  1. Which is a boolean value?
  2. Which has higher precedence?
  3. Select the string literal:
  4. Function definition keyword is:
  5. Lists are:
Answer all questions and click Submit.

๐ŸŽฅ Video Lesson

ยฉ NexIQ AI Automation Pvt Ltd | https://nexiq.netlify.app/ | hr@nexiq.in