0% found this document useful (0 votes)
2 views2 pages

Python Basics

This document provides an overview of Python programming basics, covering topics such as syntax, data types, control flow, functions, collections, file handling, error handling, and modules. It emphasizes best practices like using meaningful variable names and following the PEP8 style guide. The document encourages daily practice to enhance coding skills.

Uploaded by

suhaalluballu
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)
2 views2 pages

Python Basics

This document provides an overview of Python programming basics, covering topics such as syntax, data types, control flow, functions, collections, file handling, error handling, and modules. It emphasizes best practices like using meaningful variable names and following the PEP8 style guide. The document encourages daily practice to enhance coding skills.

Uploaded by

suhaalluballu
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/ 2

Python Programming Basics

1. Introduction

- Python is a beginner-friendly, high-level programming language.

- Widely used in web development, data science, AI, automation.

2. Syntax & Data Types

- Variables: x = 10, name = "Alice"

- Data Types: int, float, str, bool, list, tuple, dict, set

Example:

age = 21

fruits = ["apple", "banana"]

student = {"name": "Riya", "id": 101}

3. Control Flow

- if, elif, else

if age > 18:

print("Adult")

else:

print("Minor")

- for loops: for i in range(5): print(i)

- while loops: while x > 0: x -= 1

4. Functions

- Defined with def keyword.

def greet(name):

return "Hello " + name

print(greet("Suha"))

5. Collections

- List: Ordered, mutable → [1,2,3]

- Tuple: Ordered, immutable → (1,2,3)

- Dictionary: Key-value pairs → {"name":"Ali","age":20}

- Set: Unique elements → {1,2,3}


6. File Handling

with open("data.txt","r") as f:

content = f.read()

7. Error Handling

try:

x = 5/0

except ZeroDivisionError:

print("Cannot divide by zero")

8. Modules & Libraries

- import math, import random

- NumPy, Pandas, Matplotlib, Scikit-learn

9. Best Practices

- Use meaningful variable names.

- Follow PEP8 style guide.

- Comment your code.

- Break code into reusable functions.

Quick Tip: Practice small coding exercises daily to improve!

You might also like