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

Python Notes 5 Pages

The document provides an overview of Python programming, covering its basics, syntax, data types, control structures, functions, modules, data structures, and object-oriented programming concepts. Key features include Python's readability, use of indentation, and various built-in data types such as lists, tuples, and dictionaries. It also introduces classes and objects, along with essential programming principles like encapsulation and inheritance.

Uploaded by

fake786king
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 views5 pages

Python Notes 5 Pages

The document provides an overview of Python programming, covering its basics, syntax, data types, control structures, functions, modules, data structures, and object-oriented programming concepts. Key features include Python's readability, use of indentation, and various built-in data types such as lists, tuples, and dictionaries. It also introduces classes and objects, along with essential programming principles like encapsulation and inheritance.

Uploaded by

fake786king
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/ 5

Page 1: Python Basics

- Python is an interpreted, high-level, general-purpose programming language.

- Created by Guido van Rossum and first released in 1991.

- Syntax emphasizes readability and simplicity.

- Python files use the .py extension.

Basic Syntax:

- Print: print("Hello, World!")

- Comments: # This is a comment

- Variables: x = 5; name = "Alice"

- Indentation is used instead of braces.

Data Types:

- int, float, str, bool, list, tuple, dict, set


Page 2: Control Structures

Conditional Statements:

if x > 0:

print("Positive")

elif x == 0:

print("Zero")

else:

print("Negative")

Loops:

- while loop:

i=0

while i < 5:

print(i)

i += 1

- for loop:

for i in range(5):

print(i)
Page 3: Functions and Modules

Functions:

def greet(name):

return f"Hello, {name}"

- Can have default arguments, *args, and **kwargs

Modules:

- Importing: import math, from math import sqrt

- Create your own module by saving functions in a .py file

Useful Built-in Modules:

- math, datetime, os, sys, random


Page 4: Data Structures

Lists:

- Ordered, mutable

- my_list = [1, 2, 3]

- Append, remove, index, slice

Tuples:

- Ordered, immutable

- my_tuple = (1, 2, 3)

Dictionaries:

- Key-value pairs

- my_dict = {"name": "Alice", "age": 25}

Sets:

- Unordered, unique items

- my_set = {1, 2, 3}
Page 5: Object-Oriented Programming

Classes and Objects:

class Person:

def __init__(self, name, age):

self.name = name

self.age = age

def greet(self):

return f"Hello, my name is {self.name}"

p = Person("Alice", 30)

print(p.greet())

Concepts:

- Encapsulation, Inheritance, Polymorphism, Abstraction

You might also like