🐍 Python in 60 Seconds — Day 7 Numbers & Numeric Operations Python supports numbers naturally — no setup, no libraries. 🔢 Numeric types you’ll use most a = 10 → int b = 3.5 → float c = 2 + 3j → complex Most of the time, you’ll work with int and float. ➕ Basic math works as expected 5 + 2 → 7 5 - 2 → 3 5 * 2 → 10 But division has a twist 👇 ⚠️ Division surprise 5 / 2 → 2.5 Python always returns a float when dividing. You can even check it: type(5 / 2) → float If you want an integer result: 5 // 2 → 2 (floor division) 🔢 Remainder (very important) 5 % 2 → 1 Used in: • checking even / odd • cycles • conditions 🔺 Power 2 ** 3 → 8 🧠 Order matters (PEMDAS) 2 + 3 * 4 → 14 (2 + 3) * 4 → 20 Parentheses always win. 🔄 Mixing ints & floats 5 + 2.0 → 7.0 Python upgrades automatically. ⚠️ Beginner trap 0.1 + 0.2 → 0.30000000000000004 This is not a bug — it’s how computers store decimals. 🔙 Variables act like numbers Once a value is stored, Python treats the variable exactly like the number itself. x = 5 y = 3 z = x + y print(z) → 8 Python replaces x and y with their values, then performs the calculation. 🖨 Math inside print() You don’t need variables for every operation. You can do math directly inside print(): print(3 + 7) → 10 ⚠️ Important reminder about + The + operator depends on the data type: • With numbers → addition • With strings → joining Same symbol. Different meaning. 🔜There are more adbanced mathematical operations but they require an external library and it will be covered later. 💡 Insight Python is simple with numbers, but computers are not math professors — they’re approximators. 🔮 Next Strings and string operations — where text becomes powerful 😏🐍 #Python #LearnPython #Programming #Coding #TechCareers #DataScience #100DaysOfCode
Python Numbers and Operations in 60 Seconds
More Relevant Posts
-
PYTHON JOURNEY - Day 46 / 50..!! TOPIC – Python Modules Today I explored Modules — a way to organize code into separate files and use pre-written code from Python’s massive library. It’s like having a giant toolbox where you only pick the tools you need! 1. Importing Built-in Modules Python comes with many "batteries included" modules. To use them, we simply use the import keyword. Python import math print(math.sqrt(64)) # Output: 8.0 print(math.pi) # Output: 3.14159... 2. Using the random Module Perfect for games or selecting random data. Python import random options = ["Rock", "Paper", "Scissors"] print(random.choice(options)) # Picks a random item print(random.randint(1, 10)) # Random number between 1 and 10 3. Using alias and from You can give a module a nickname or import only a specific part of it to save memory. Python import datetime as dt from math import factorial print(dt.datetime.now()) print(factorial(5)) # Output: 120 Why Use Modules? Efficiency: Don't reinvent the wheel! Use proven code written by experts. Organization: Keep your project files clean by separating logic. Power: Modules allow Python to do everything from web scraping to Data Science and AI. Mini Task Write a program that: Imports the random module. Creates a list called players = ["Alice", "Bob", "Charlie", "David"]. Uses random.choice() to pick a random "Winner" from the list. Prints: "And the winner is... <name>! #Python #PythonLearning #50DaysOfPython #DailyCoding #LearnPython #CodingJourney #PythonForBeginners #LinkedInLearning #DeveloperCommunity
To view or add a comment, sign in
-
-
Python with Machine Learning — Chapter 2 📘 Topic: Python Data Types 🔍 Let's keep building your foundation. Data types tell Python what kind of value you're working with. Mastering them helps you avoid bugs and write cleaner code. Here are 5 essential types we'll use in ML: 1. Integer — whole numbers → counts, indices, labels 2. Float — decimal numbers → prices, measurements, probabilities 3. String — text → names, messages, file paths 4. Boolean — True or False → conditions, decisions 5. None → missing values or placeholders [CODE] # Integers and Floats age = 25 pi = 3.14 # Strings name = "Alice" # Boolean is_active = True # None missing_value = None print(age, pi, name, is_active, missing_value) [/CODE] Methods and functions • String methods: name.lower(), name.upper(), name.strip() • Type conversion: int(), float(), str(), bool() Quick tips • Use type() to check a variable's type • Start simple and build confidence with small experiments You're doing great. Keep practicing. Next up: Lists
To view or add a comment, sign in
-
Python with Machine Learning — Chapter 9 📘 Topic: Python Class 🔍 Today, we're diving into a core concept: the Python Class. Think of a class as a blueprint for creating objects. It helps us organize our code in a clean, reusable way—like a recipe for making cookies! 🍪 **Why it matters in real-world learning:** In machine learning and data science, classes help us structure complex models and data pipelines. They make our code modular and easier to debug. Learning this now builds a strong foundation for advanced topics later. You've got this! 💪 **Constructor: Your Object's First Step** A constructor is a special method inside a class that runs automatically when you create a new object. Its job is to set up the object's initial state—like adding ingredients when you bake a cookie. In Python, the constructor is always named `__init__`. Let's see a simple example: [CODE] class Cookie: def __init__(self, flavor, color): self.flavor = flavor # Attribute set by constructor self.color = color print(f"A new {self.color} {self.flavor} cookie is ready!") # Create a cookie object choco_cookie = Cookie("chocolate", "brown") [/CODE] Here, `__init__` takes parameters `flavor` and `color` and assigns them to the object's attributes using `self`. When we create `choco\_cookie`, the constructor runs and prints a welcome message. Key takeaway: Every class can have one `__init__` constructor to initialize objects. It's your go-to tool for setting up data. Practice this in your code! Try creating your own class. Share your thoughts or questions below—I'm here to guide you. 🚀 #Python #MachineLearning #Beginners #Coding
To view or add a comment, sign in
-
"Python Mini-Series Wrap-Up: What writing production-ready Python really looks like" Over the last few posts, I shared a short Python mini-series focused on how Python is actually used in analytics and data engineering — beyond tutorials and toy examples. The core idea across the series was simple: Python becomes valuable when it’s structured, trusted, and built to scale. Here’s what I covered: • Post 1 – Structure: Treat Python work like a pipeline, not a one-off notebook • Post 2 – Unstructured data: Turning PDFs and messy text into structured datasets with regex • Post 3 – Trust: Making data quality a first-class citizen through validation and checks • Post 4 – Scale: Writing faster, more memory-efficient code with vectorization and smart data types • Post 5 – Maturity: Early mistakes that taught me why reproducibility and structure matter None of this is flashy — and that’s the point. These are the habits that turn Python scripts into workflows teams can rely on, and analyses into outputs stakeholders actually trust. If you’re early in your data career, you don’t need advanced tricks to stand out. Focus on writing Python that is: ✔ reproducible ✔ configurable ✔ readable by someone else ✔ safe to run more than once That’s what moves your work closer to production. I’ll be shifting next into SQL, using the same practical, real-world lens. 👉 Follow along — more coming soon.
To view or add a comment, sign in
-
🐍 Python in 60 Seconds — Day 8 Strings & String Operations Strings are how Python works with text. Anything inside quotes is a string. Example: text = "Python" You can use: • single quotes ' ' • double quotes " " Both work the same. ➕ Joining strings "Hello" + "World" → "HelloWorld" ⚠️ No spaces are added automatically. If you want a space, include it: "Hello " + "World" → "Hello World" 🔁 Repeating strings "Hi" * 3 → "HiHiHi" Yes, Python allows this 😄 📏 Length of a string len("Python") → 6 Spaces count too. 🔢 Strings are indexed word = "Python" word[0] → 'P' word[1] → 'y' word[-1] → 'n' Indexing starts at 0. Negative indices mean starting from the end, and they begin at -1. ⚠️ Beginner trap word[6] → Error (index out of range) Indexes must stay inside the string. 🔤 Escape characters (important ❗) An escape character is a special sequence that starts with a backslash \ It tells Python to treat the next character in a special way. They are characters inside the string, not commands. 📄 New line print("Hello\nWorld") Output: Hello World \n means “start a new line”. 📐 Tab (spacing) print("A\tB\tC") Output: A B C \t inserts horizontal spacing. 🔔 Common escape characters " → double quote ' → single quote \n → new line \t → tab ✅ Examples print("He said: \"Hello\"") print('It\'s Python') print("C:\\new\\text") 🧠 Key idea A string is not “one thing” — it is a sequence of characters, each with a position. 💡 Insight Numbers are for calculation. Strings are for expression. Python treats both as first-class citizens. 💫 Keep Experiementing! 🔮 Tomorrow String slicing & powerful text tricks #Python #LearnPython #Programming #Coding #TechCareers #DataScience #100DaysOfCode
To view or add a comment, sign in
-
-
Python for Almost Everything As I continue learning Python, I’m starting to realize why it’s so widely used across different tech fields. Python becomes powerful when combined with the right libraries. Here’s what I’m learning Python can be used for: 📊 Data Science & Machine Learning → Python + Pandas → Data manipulation → Python + Matplotlib / Seaborn → Data visualization → Python + TensorFlow → Machine learning & deep learning 🌐 Web Development → Python + Flask → Simple web apps → Python + Django → Large-scale applications → Python + FastAPI → Fast APIs 🤖 Automation & Scraping → Python + BeautifulSoup → Web scraping → Python + Selenium → Browser automation 💾 Other Powerful Uses → Python + SQLAlchemy → Databases → Python + OpenCV → Computer vision What I find interesting is that Python isn’t limited to one role; the same language grows with you as your skills grow. Which Python library did you start with? #Python #DataScienceJourney #LearningInPublic #BeginnerInTech #TechCareers
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟯𝟴: 𝗪𝗵𝘆 𝗬𝗼𝘂𝗿 𝗣𝘆𝘁𝗵𝗼𝗻 𝗖𝗼𝗱𝗲 𝗪𝗼𝗿𝗸𝘀… 𝗯𝘂𝘁 𝗙𝗲𝗲𝗹𝘀 𝗦𝗹𝗼𝘄. Have you ever written Python code that gives correct results, but takes way too long to run? Most of the time, the problem isn’t Python itself. It’s how we use it. Here are the most common performance mistakes I’ve learned to avoid 👇 𝟭. 𝗨𝘀𝗶𝗻𝗴 𝗹𝗼𝗼𝗽𝘀 𝘄𝗵𝗲𝗿𝗲 𝘃𝗲𝗰𝘁𝗼𝗿𝗶𝘇𝗮𝘁𝗶𝗼𝗻 𝗶𝘀 𝗽𝗼𝘀𝘀𝗶𝗯𝗹𝗲 Python loops are slow - especially over large datasets. ❌ Looping row by row ✅ Using Pandas / NumPy vectorized operations Vectorized code is not just shorter, it’s significantly faster. 𝟮. 𝗔𝗽𝗽𝗹𝘆𝗶𝗻𝗴 𝗳𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀 𝗿𝗼𝘄-𝘄𝗶𝘀𝗲 𝗶𝗻 𝗣𝗮𝗻𝗱𝗮𝘀 Using .apply() feels convenient, but it often behaves like a hidden loop. Before using apply, ask: • Can this be done with built-in Pandas functions? • Can it be expressed as a vectorized operation? Most of the time - yes. 𝟯. 𝗟𝗼𝗮𝗱𝗶𝗻𝗴 𝗺𝗼𝗿𝗲 𝗱𝗮𝘁𝗮 𝘁𝗵𝗮𝗻 𝘆𝗼𝘂 𝗻𝗲𝗲𝗱 Reading entire tables or files when only a few columns are required wastes: • Memory • Time • Compute resources Always filter: • Columns • Rows • Date ranges as early as possible. 𝟰. 𝗥𝗲𝗰𝗮𝗹𝗰𝘂𝗹𝗮𝘁𝗶𝗻𝗴 𝘁𝗵𝗲 𝘀𝗮𝗺𝗲 𝗹𝗼𝗴𝗶𝗰 𝗿𝗲𝗽𝗲𝗮𝘁𝗲𝗱𝗹𝘆 If the same computation runs inside a loop or function multiple times: • Cache it • Store it once • Reuse the result Repeated computation silently kills performance. 𝟱. 𝗜𝗴𝗻𝗼𝗿𝗶𝗻𝗴 𝗱𝗮𝘁𝗮 𝘁𝘆𝗽𝗲𝘀 Wrong data types slow everything down. Examples: • Using an object instead of a category • Using float where int is enough • Storing dates as strings Correct dtypes = faster operations + lower memory usage. Python is fast enough for most data tasks; inefficient patterns are usually the real bottleneck. Writing efficient code matters as much as writing correct code. 𝗪𝗵𝗮𝘁 𝗣𝘆𝘁𝗵𝗼𝗻 𝗽𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 𝗶𝘀𝘀𝘂𝗲 𝘀𝘂𝗿𝗽𝗿𝗶𝘀𝗲𝗱 𝘆𝗼𝘂 𝘁𝗵𝗲 𝗺𝗼𝘀𝘁 𝘄𝗵𝗲𝗻 𝘆𝗼𝘂 𝗱𝗶𝘀𝗰𝗼𝘃𝗲𝗿𝗲𝗱 𝗶𝘁? 𝗟𝗲𝘁’𝘀 𝘀𝗵𝗮𝗿𝗲 𝗹𝗲𝗮𝗿𝗻𝗶𝗻𝗴𝘀 👇 #Python #DataScience #PerformanceOptimization #Pandas #NumPy #Analytics #Learning #CodingTips
To view or add a comment, sign in
-
🚀 From String Splits to Structured Data: A Quick Python Evolution Ever watched a simple Python script evolve? 😄 Started with extracting first names from a list: names = ["Charles Oladimeji", "Ken Collins"] fname = [] for i in names: fname.append(i.split()[0]) # Result: ['Charles', 'Ken'] Then flipped to last names: fname.append(i.split()[1]) # Result: ['Oladimeji', 'Collins'] Finally transformed it into clean, structured dictionaries: names = ["Charles Oladimeji", "Ken Collins", "John Smith"] fname = [] for i in names: parts = i.split() fname.append({"first": parts[0], "last": parts[1]}) # Result: [{'first': 'Charles', 'last': 'Oladimeji'}, ...] Why I love this progression: 1. Shows how small tweaks solve different problems 2. Demonstrates data structure thinking (list → list of dicts) 3. Real-world applicable for data cleaning/API responses 4. Sometimes the most satisfying code journeys start with a simple .split()! #DataEngineer #Python #Coding #DataTransformation #Programming
To view or add a comment, sign in
-
-
🐍 Python in 60 Seconds — Day 14 Logical Operators — Making Decisions Smarter Sometimes one condition isn’t enough. Real-world logic needs more than a single True or False. That’s where logical operators come in 👇 🔗 and — All conditions must be True age = 22 if age > 18 and age < 30: print("Young adult") ✔️ Every condition must pass ❌ One failure → the whole condition fails 🔀 or — At least one condition is True day = "Saturday" if day == "Friday" or day == "Saturday": print("Weekend!") Perfect for alternatives and choices. 🚫 not — flips the logic is_raining = False if not is_raining: print("Go outside") not True → False not False → True 🧠 Mixing and & or — Parentheses matter Python follows precedence rules: not → and → or So this: A or B and C is read by Python as: A or (B and C) ⚠️ This is not always what you intend. ✅ Grouping conditions with parentheses If your logic is: (Condition1 OR Condition2) AND Condition3 You must group it explicitly 👇 if (condition1 or condition2) and condition3: print("Condition met") Now Python thinks the same way you do. 🧠 Real-world example Allow access if: User is admin OR moderator AND the account is active role = "admin" is_active = True if (role == "admin" or role == "moderator") and is_active: print("Access granted") ✔️ Admin + active → allowed ✔️ Moderator + active → allowed ❌ Inactive account → denied This is how real systems make decisions. ⚠️ Beginner Trap if age > 18 and < 30: # ❌ Error ✅ Correct: if age > 18 and age < 30: Python needs complete comparisons — no shortcuts. 🧠 Key Takeaways and → all conditions or → any condition not → reverse logic ( ) → control the logic flow 💡 Insight Logical operators don’t make programs complex — they make them precise. 🔮 Tomorrow Nested conditions & decision trees — thinking step by step 🌳🐍 #Python #LearnPython #Programming #Coding #TechCareers #DataScience #100DaysOfCode
To view or add a comment, sign in
-
-
Linear Regression in Excel vs Python — Same Model, Same Result Linear Regression is usually associated with Python or R. But rebuilding the same model side by side in Excel and Python (scikit-learn) was a great reminder that tools change, fundamentals don’t. Using the same dataset and query value, I implemented linear regression in both environments: Excel • Used SLOPE, INTERCEPT, and RSQ • Visualized the model with a scatter plot and trendline • Predicted value calculated directly using the regression equation Python • Built the model using scikit-learn • Generated predictions programmatically • Displayed the predicted point and R² score directly on the chart Key takeaways: • Excel makes the math behind regression very transparent • Python offers clean, scalable workflows for modeling • Seeing the predicted value on the plot improves intuition • R² becomes more meaningful when paired with visualization • A familiar tool like Excel can still be a powerful learning lab This exercise reinforced an important lesson for me: understanding the algorithm matters more than the tool you use to implement it. #MachineLearning #LinearRegression #Excel #Python #DataAnalytics
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development