BASIC PYTHON
CONCEPTS
A Beginner's Guide to
Python Programming
By Nithish
1. Variables and Data Types
Variables store data values.
Common Data Types
-int(integer)
-float(decimal)
-str(string)
-bool(boolean)
Code Example
x = 5# int
y = 3.14 # float
name = "Nithish" # str
is_valid = True # bool
2. Control Structures
if-else Statements:
Conditional statements allow decision-
making.
If a condition is true, perform an action.
Code Example
if x > y:
print("x is greater than y")
else:
print("x is less than or equal
to y")
Loops
Use loops to repeat actions.
Types:
for loop
while loop
Code Example
for i in range(5):
print(i)
while x > 0:
print(x)
x -= 1
3. Functions
Functions help to reuse blocks of code.
Define a function using def keyword.
Code Example
def greet(name):
return f"Hello, {name}!"
print(greet("Nithish"))
4. Lists and Tuples
Lists are mutable
Tuples are immutable.
Use lists to store multiple items.
Code Example
my_list = [1, 2, 3, 4] # List
my_tuple = (1, 2, 3, 4) # Tuple
5. Dictionaries
Store data in key-value pairs.
Access values using keys.
Code Example
my_dict = {"name": "Nithish", "age": 25}
print(my_dict["name"]) # Outputs:
Nithish
6. Classes and Objects (OOP)
Classes define blueprints for objects.
Objects are instances of classes.
Code Example
def _init_(self, name, age):
self.name = name
self.age = age
def introduce(self):
return f"My name is
{self.name} and I am {self.age} years
old."
person1 = Person("Nithish", 25)
print(person1.introduce())
7. File Handling
Read from or write to files in Python.
Open files using with statement.
Code Example
with open('file.txt', 'r') as file:
content = file.read()
print(content)
Thank
!you !
Stay curious and keep coding!