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

PYTHON

Gives a full beginners guide on how to learn python basic concepts and inituiatives

Uploaded by

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

PYTHON

Gives a full beginners guide on how to learn python basic concepts and inituiatives

Uploaded by

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

Here’s a concise summary of key Python concepts for beginners:

### 1. **Basic Syntax**

- **Print statement**: Displays output on the screen.

```python

print("Hello, World!")

```

- **Comments**: Use `#` for single-line comments, and triple quotes `""" """` for multi-line comments.

```python

# This is a single-line comment

"""

This is a

multi-line comment

"""

```

### 2. **Variables and Data Types**

- **Variables** store data values.

```python

name = "Alice"

age = 25

```

- **Common Data Types**:


- `int` (integer), `float` (decimal), `str` (string), `bool` (boolean), `list`, `tuple`, `dict`, `set`

```python

number = 10 # int

price = 19.99 # float

is_active = True # bool

fruits = ["apple", "banana"] # list

```

### 3. **Control Flow**

- **If-else statements**: Conditional logic.

```python

if age >= 18:

print("Adult")

else:

print("Minor")

```

- **Loops**: Repeat code using `for` or `while`.

```python

for i in range(5): # Loop from 0 to 4

print(i)

while age < 30:

age += 1
print(age)

```

### 4. **Functions**

- **Functions** define reusable blocks of code.

```python

def greet(name):

print(f"Hello, {name}!")

greet("Bob") # Calling the function

```

### 5. **Data Structures**

- **List**: Ordered, mutable collection.

```python

fruits = ["apple", "banana", "cherry"]

fruits.append("orange") # Add item

```

- **Tuple**: Ordered, immutable collection.

```python

coordinates = (10, 20)

```

- **Dictionary**: Unordered collection of key-value pairs.


```python

person = {"name": "Alice", "age": 25}

```

- **Set**: Unordered collection of unique items.

```python

unique_numbers = {1, 2, 3, 4}

```

### 6. **Object-Oriented Programming (OOP)**

- **Class**: Blueprint for creating objects.

```python

class Dog:

def __init__(self, name, breed):

self.name = name

self.breed = breed

def bark(self):

print(f"{self.name} says woof!")

dog1 = Dog("Buddy", "Golden Retriever")

dog1.bark()

```

- **Objects** are instances of classes. They hold data (attributes) and behavior (methods).
### 7. **File Handling**

- Open and work with files using `open()`.

```python

with open('file.txt', 'w') as file:

file.write("Hello, Python!")

```

### 8. **Error Handling**

- Use `try`, `except` to handle exceptions.

```python

try:

x = 10 / 0

except ZeroDivisionError:

print("Cannot divide by zero!")

```

### 9. **Modules and Libraries**

- Python includes built-in libraries like `math`, `datetime`, etc.

```python

import math

print(math.sqrt(16)) # Output: 4.0

```

### 10. **List Comprehensions**


- A concise way to create lists.

```python

squares = [x**2 for x in range(5)]

print(squares) # Output: [0, 1, 4, 9, 16]

```

---

### Key Python Concepts Recap:

- **Variables** store data.

- **Control flow** (if-else, loops) dictates program behavior.

- **Functions** encapsulate reusable logic.

- **Data structures** (list, tuple, dict, set) organize data.

- **OOP** helps model real-world entities.

- **Error handling** improves program robustness.

- **Modules** add extra functionality.

- **List comprehensions** simplify code.

By practicing these basics, you'll build a strong foundation in Python!

You might also like