Posts

Showing posts with the label python

Python OOP — Classes, Objects, and More | OOP made less scary, maybe! | TechAmbitionX

Image
Python OOP — Classes, Objects, and More | TechAmbitionX What is this Object-Oriented Programming thing? (OOP) Alright, let's break it down. OOP is a programming paradigm that uses "objects" to design software. Think of objects as real-world entities like cars, dogs, or even you! Each object has attributes (characteristics) and methods (actions). Easy Explanation: Imagine you want to describe something in real life, like a dog. You'd say what it looks like (its color, size) and what it can do (bark, run). OOP lets us write code that works the same way — by creating "things" (objects) with their own features and actions. Classes and Objects A class is like a blueprint for creating objects. An object is an instance of a class. Let's see an example: class Dog: def __init__(self, name): self.name = name def bark(self): print(f"{self.name} says woof!") my_dog = Dog("Doggy...

What the hell are functions in Python | TechAmbitionX | An easy guide by Mr. BILRED

Image
Python Functions — Defining, Returning & Using Arguments | TechAmbitionX What the hell is a Function in Python? Okay relax, you might've not opened the book, and exam is around the corner, but still, there's hope. HOPE! What is a Function? A function is a reusable block of code that performs a specific task. Functions help you organize code, avoid repetition, and make programs easier to understand. Got it? Creating Functions with def def greet(): print("Hello, TechAmbitionX!") This defines a function named greet . To use it, call it like this: greet() # Output: Hello, TechAmbitionX! Returning Values with return Functions can return values instead of printing them. This makes your code more flexible. def add(a, b): return a + b result = add(5, 3) print(result) # Output: 8 print() vs return print() displays output immediately. return sends data back to where the function was called, so you can store or use it later. ...

User Input in Python | Python Notes By Mr. BILRED - TechAmbitionX

Image
User Input in Python — Learn input(), int(), float(), and getpass() | TechAmbitionX User Input in Python — Talk to Your Code! What is User Input? User input means taking data from the user while the program is running . In Python, we use the built-in input() function. Basic Example name = input("What's your name? ") print("Hello, " + name + "!") Output: What's your name? Mr. BILRED Hello, Mr. BILRED! Want Numbers? Convert Them input() always returns a string . If you want a number, convert it like this: age = int(input("Enter your age: ")) print(age + 1) You Can Use float() too gpa = float(input("Enter your GPA: ")) print("apki GPA times 2 is", gpa * 2) Use Inputs in Real Programs username = input("Username: ") password = input("Password: ") print(f"Logging in as {username}...") 🔐 Optional: Hide Sensitive Input from getpass import getpass password = get...

Strings In Python - Python Notes By Mr. BILRED | TechAmbitionX

Image
Strings in Python — Say Hello to Text | TechAmbitionX Strings in Python — Say Hello to Text A string in Python is just a bunch of characters inside quotes. Single quotes or double quotes — both work: name = "Bilal" greeting = 'Hello World' empty = "" They can contain numbers, symbols, even emojis: info = "Python 3.11 rocks! 🤘" How to Use Strings in Python 1. Concatenation (Joining Strings) first = "Mr. " last = "BILRED" full = first + last print(full) # Mr. BILRED 2. String Length name = "Bilal" print(len(name)) # 5 3. Accessing Characters name = "Bilal" print(name[0]) # B print(name[-1]) # l 4. Slicing Strings (obv that means k "kaatna") print(name[0:3]) # Bil print(name[:4]) # Bila print(name[2:]) # lal 5. String Methods msg = "python is awesome" print(msg.upper()) # PYTHON IS AWESOME print(msg.capitalize()) # Python...

What Are Variables In Python - Python Notes By Mr. BILRED - TechAmbitionX

Image
What Are Variables in Python? | TechAmbitionX What Are Variables in Python? Alright, let’s keep it simple. A variable is just a name that stores some value . Like a box with a label on it. When you write: x = 5 You’re saying: “Hey Python, make a box called x , and put the number 5 inside it.” Some Examples: name = "Bilal" age = 21 pi = 3.14 You can use these variables later in your program: print(name) print(age + 1) Variables Can Store: Numbers ( int , float ) Text (called strings ) Boolean values ( True or False ) Lists, dictionaries, and more Variable Naming Rules: In x = 10 "x" is the identifier for the variable storing the value 10. Try not to forget the following rules Don’t start names with a number No spaces allowed (use underscores like user_name ) Use meaningful names (atleast when you're showing that to your boss) Wanna Try? x = "Mr. BILRED" print("Welcom...