This file provides a concise yet comprehensive overview of Python's fundamental concepts, offering a simplified introduction to the language's key elements, making it an ideal starting point for gaining a solid understanding.
- Create a new Python file (e.g.,
hello.py
) using a code editor. - Add the following code to print "Hello, World!" to the console:
print("Hello World!!")
Python supports various data types:
# Integer
x = 10
# Float
y = 3.14
# String
name = "Alice"
# Boolean
is_student = True
Perform arithmetic and logical operations:
# Arithmetic
sum = x + y
difference = x - y
product = x * y
division = x / y
remainder = x % 3
# Logical
and_result = True and False
or_result = True or False
not_result = not True
Make decisions with conditional statements:
if x > y:
print("x is greater than y")
elif x == y:
print("x is equal to y")
else:
print("x is less than y")
Execute code repeatedly using loops:
# For loop
for i in range(5):
print(i)
# While loop
counter = 0
while counter < 5:
print(counter)
counter += 1
Explore common data structures:
# List
fruits = ["apple", "banana", "cherry"]
# Dictionary
person = {"name": "John", "age": 30, "is_student": False}
Create reusable code blocks with functions:
def greet(name):
print("Hello, " + name + "!")
greet("Alice")
Interact with users using input and output:
user_input = input("Enter your name: ")
print("Hello, " + user_input + "!")
Document your code using comments:
# This is a single-line comment
"""
This is a
multi-line comment
"""
Handle errors gracefully using try-except blocks:
try:
result = x / 0
except ZeroDivisionError:
print("Error: Division by zero")
Welcome to the world of Python! This guide is designed to help experienced developers quickly grasp the fundamentals of Python programming. Whether you're transitioning from other languages or expanding your skillset, this repository will give you the essential tools to start building with Python.