Python Fundamentals
Duration: 5 min
Running Python Code
Python code can be run in two ways: interactively in the Python shell, or by running a script file. Let's start with a simple script.
# Your first Python program
print('Hello, AI!')
# Variables
name = 'Alice'
age = 25
print(f'My name is {name} and I am {age} years old')Hello, AI!
My name is Alice and I am 25 years oldData Types and Lists
# Numbers
age = 25
height = 5.9
# Strings
name = 'Alice'
# Lists (ordered collections)
fruits = ['apple', 'banana', 'orange']
print(fruits[0]) # Access first item
# Dictionaries (key-value pairs)
person = {'name': 'Alice', 'age': 25, 'city': 'NYC'}
print(person['name'])apple
AliceFunctions
# Define a function
def greet(name):
return f'Hello, {name}!'
# Call the function
result = greet('Alice')
print(result)
# Function with multiple parameters
def add(a, b):
return a + b
print(add(5, 3))Hello, Alice!
8Learn More Python
Ready to dive deeper? Take the Python Fundamentals course to master loops, conditionals, file handling, and more.
❓ What is the correct way to create a list in Python?