0% found this document useful (0 votes)
4 views4 pages

Python Fundamentals Guide Final

This document serves as a beginner's guide to Python fundamentals, covering variables, data types, control flow, data structures, functions, modules, error handling, input/output, and file handling. It emphasizes the importance of practice and suggests next steps for further learning, such as exploring object-oriented programming and web frameworks. The guide encourages small projects to build confidence in coding.

Uploaded by

Maciej Karoń
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Python Fundamentals Guide Final

This document serves as a beginner's guide to Python fundamentals, covering variables, data types, control flow, data structures, functions, modules, error handling, input/output, and file handling. It emphasizes the importance of practice and suggests next steps for further learning, such as exploring object-oriented programming and web frameworks. The guide encourages small projects to build confidence in coding.

Uploaded by

Maciej Karoń
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Python Fundamentals: A Beginners Guide

Variables and Data Types


In Python, you dont need to declare variable types Python figures it out for you.

name = "Alice" # String


age = 30 # Integer
height = 5.6 # Float
is_student = True # Boolean

Common Data Types:


- int: Whole numbers (10)
- float: Decimal numbers (3.14)
- str: Text ("Hello")
- bool: Boolean values (True / False)
- list, tuple, dict, set: Collections

Control Flow
Python uses indentation (usually 4 spaces) to define blocks of code.

if statements:
if age >= 18:
print("Adult")
else:
print("Minor")

for loops:
for i in range(5):
print(i) # 0 to 4

while loops:
count = 0
while count < 3:
print(count)
count += 1

Data Structures
Lists (Ordered, changeable, allow duplicates):
fruits = ["apple", "banana", "cherry"]
fruits.append("orange")

Tuples (Ordered, immutable):


dimensions = (10, 20)

Dictionaries (Key-value pairs):


person = {"name": "Alice", "age": 30}
print(person["name"])

Sets (Unordered, no duplicates):


unique_numbers = {1, 2, 3, 3} # {1, 2, 3}

Functions
Functions allow you to reuse code.

def greet(name):
return f"Hello, {name}!"

print(greet("Bob"))

Modules and Imports


Python has a huge standard library and supports custom modules.

import math
print(math.sqrt(16)) # 4.0

You can also create your own .py files and import them.
Error Handling
Use try...except to catch exceptions:

try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero.")

Input and Output


Input from user:
name = input("Enter your name: ")

Output to console:
print("Hello", name)

File Handling
Reading from and writing to files:

# Writing to a file
with open("example.txt", "w") as file:
file.write("Hello, file!")

# Reading from a file


with open("example.txt", "r") as file:
content = file.read()

Next Steps
Once youve mastered the fundamentals, you can explore:
- Object-Oriented Programming (OOP)
- Web frameworks (Flask, Django)
- Data analysis (Pandas, NumPy)
- Automation (Selenium, pyautogui)

Final Tip
Practice consistently. Python is readable and beginner-friendly, but mastering it requires writing
code regularly.
Try small projects like a calculator, a to-do app, or a simple game to build confidence.

You might also like