Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

python fundamentals

Introduction to Python

Uploaded by

MARK SIMIYU
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

python fundamentals

Introduction to Python

Uploaded by

MARK SIMIYU
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

It seems you meant "Fundamentals of Python".

Here’s a quick overview of Python


fundamentals:

1. Introduction to Python

• Python is a high-level, interpreted programming language.


• It is known for its simplicity and readability.
• Common use cases: web development, data science, automation, AI, and more.

2. Basic Syntax

• Python uses indentation (not braces) to define blocks of code.


• Comments are written using #.

# This is a comment
print("Hello, World!") # Prints output

3. Variables and Data Types

• Variables are dynamically typed (no need to declare type).


• Common data types:
o int (integer)
o float (decimal numbers)
o str (strings)
o bool (True/False)

x = 5 # int
y = 3.14 # float
name = "Isaac" # str
is_active = True # bool

4. Control Flow

• Conditional Statements: if, elif, else


• Loops: for and while

# If-else example
age = 18
if age >= 18:
print("Adult")
else:
print("Minor")
# Loop example
for i in range(5):
print(i)

5. Functions

• Functions are defined using def.

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

print(greet("Isaac"))

6. Data Structures

• Lists: Ordered, mutable collections.


• Tuples: Ordered, immutable collections.
• Dictionaries: Key-value pairs.
• Sets: Unordered, unique elements.

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

# Dictionary
person = {"name": "Isaac", "age": 28}

# Set
unique_numbers = {1, 2, 3}

7. Modules and Libraries

• Python has built-in and third-party modules.


• Example: math, random, os, numpy.

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

8. File Handling

• Open, read, write, and close files.

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


file.write("Hello, Python!")
9. Object-Oriented Programming

• Classes and objects allow modular programming.

class Person:
def __init__(self, name):
self.name = name

def greet(self):
return f"Hi, I’m {self.name}!"

p = Person("Isaac")
print(p.greet())

Would you like to explore a specific topic further?

You might also like