🐍 Python in 60 Seconds — Day 5 User Input & Typecasting This is where Python starts talking back to you 😄 🧑💻 Getting input from the user name = input("Enter your name: ") Let’s say the user types: World print("Hello", name) → Hello, World ⚠️ Important rule (memorise this) input() always returns a string even if numeric data is inputed . Example: x = input("Enter a number: ") print(x + x) Input: 5 Output: 55 ❗ Why? Because "5" + "5" is text joining, not math. 🔄 Typecasting (telling Python what you mean) Typecasting means converting one data type into another. To turn user input into numbers: age = int(input("Enter your age: ")) height = float(input("Enter your height: ")) Now Python knows these are numbers, not text. ➕ Now Python can do math print(age + 1) ✅ This works Because age is an int, not a string. ❌ Common beginner mistake age = input("Enter your age: ") print(age + 1) → Error 🚫 Python won’t guess what you want. You must be explicit. 💡 Insight Python is flexible — but not psychic 🧠 You decide what a value means. Consistency beats motivation. Next: Typecasting in depth #Python #LearnPython #Programming #Coding #TechCareers #DataScience #10DaysOfCode
Python User Input & Typecasting Basics
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 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
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
-
-
🚀 Day 6: Top Learning – Strings, Indexing & Slicing (Python) Strings look simply… but they are extremely powerful in Python. 🔹 What is a String? A string simply means text. Examples: "abc" "123" 'abc' Anything inside quotes is treated as a string. 🔹 String Indexing (Accessing Characters) Every character in a string has a position called an index. Left to Right (Forward Indexing): A m a y 0 1 2 3 Right to Left (Backward Indexing): A m a y -4 -3 -2 -1 This helps you access characters from both directions. 🔹 String Slicing (Very Powerful Concept 🔥) String slicing allows you to extract parts of a string. You can easily get: ✔ First character ✔ Last character ✔ Middle character(s) ✔ Any portion of the main string This concept is heavily used in: 📊 Data Cleaning 📂 Text Processing 📈 Real-world Data Analysis ✅ Key Learning of the Day “Master strings, and you master how Python talks to data.” Step-by-step learning. Strong basics. Long-term confidence Satish Dhawale SkillCourse #Python #PythonBasics #Strings #StringSlicing #DataAnalytics #LearningJourney #CodingForBeginners #Day6Learning
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
-
-
🔤 Master These Python String Methods & Level Up Your Code 🚀 Strings are everywhere in Python from user input to data processing. If you know these core string methods, your code instantly becomes cleaner, safer, and more professional. ✨ Must-know methods: • split() --> Break a sentence into words for text analysis • strip() --> Clean extra spaces from user input • join() --> Combine list items into a single string • replace() --> Update or sanitize text values • upper() --> Convert text to uppercase for consistency • lower() --> Normalize text for case-insensitive comparison • isalpha() --> Validate name fields (letters only) • isdigit() --> Check if input contains only numbers • startswith() --> Verify prefixes like country codes or URLs • endswith() --> Validate file extensions (.pdf, .jpg, etc.) • find() --> Locate a word or character inside a string 💡 Why they matter? ✔ Clean messy user input ✔ Validate data effortlessly ✔ Write readable, efficient logic ✔ Avoid common bugs in real projects If you’re learning Python , bookmark this 📌 Keep up the 𝐏𝐫𝐚𝐜𝐭𝐢𝐜𝐞 👍 𝐂𝐨𝐧𝐬𝐢𝐬𝐭𝐞𝐧𝐜𝐲 is the 𝐊𝐞𝐲 in 𝐏𝐫𝐨𝐠𝐫𝐚𝐦𝐦𝐢𝐧𝐠 💯 👇 Comment “Python” if you want a part-2 with real examples! #Python #PythonProgramming #Coding #LearnToCode #Developer #ProgrammingTips #CleanCode
To view or add a comment, sign in
-
-
Building a Wikipedia Search Engine in 10 Lines of Python! I’ve always been fascinated by how a few lines of clean code can bridge the gap between us and the world's information. I recently put together this mini-project: a Wikipedia Search Engine built entirely in Python. By leveraging the wikipedia library, I was able to create a script that takes a user keyword and instantly pulls a concise summary directly from the web. 🛠️ How it works: Library: Using the wikipedia wrapper to handle API requests seamlessly. Input: A simple user prompt to capture the search topic. Execution: The summary function fetches the first few sentences of the entry. Output: Clean, formatted results delivered straight to the terminal. It’s projects like these that remind me why Python is such a powerhouse for automation and data retrieval. It’s not just about the code; it’s about making information more accessible with minimal overhead. The Code: Python: import wikipedia topic = input("Enter keyword to search: ") print("="*30) print(f"Searching for: {topic}") print("="*30) res = wikipedia.summary(topic, sentences=3) print(res) print("="*30) What was the first "useful" script you ever wrote? Let’s talk about it in the comments! 👇 #Python #Coding #Automation #OpenSource #DataScience #SoftwareDevelopment #TechCommunity
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
-
𝗗𝗮𝘆 𝟯𝟴: 𝗪𝗵𝘆 𝗬𝗼𝘂𝗿 𝗣𝘆𝘁𝗵𝗼𝗻 𝗖𝗼𝗱𝗲 𝗪𝗼𝗿𝗸𝘀… 𝗯𝘂𝘁 𝗙𝗲𝗲𝗹𝘀 𝗦𝗹𝗼𝘄. 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
-
PYTHON JOURNEY - Day 47 / 50..!! TOPIC – List Comprehensions Today I explored one of Python’s most "elegant" features — List Comprehensions. It’s a shorthand way to create new lists based on existing ones, turning 4 lines of code into just 1! 1. The Traditional Way vs. Comprehension Normally, to create a list of squares, you’d need a for loop and .append(). With comprehension, it’s a single line! Python # Traditional Way nums = [1, 2, 3] squares = [] for x in nums: squares.append(x * x) # List Comprehension (The Pythonic Way) squares = [x * x for x in nums] print(squares) # Output: [1, 4, 9] 2. Adding a Condition (The if part) You can filter items while creating the list. Python prices = [10, 55, 80, 25, 100] # Only keep prices over 50 expensive = [p for p in prices if p > 50] print(expensive) # Output: [55, 80, 100] 3. String Manipulation It works perfectly for transforming text data too. Python names = ["srikanth", "python", "dev"] capitalized = [n.capitalize() for n in names] print(capitalized) # Output: ['Srikanth', 'Python', 'Dev'] Why Use List Comprehensions? Readability: Once you learn the syntax, it's much easier to read at a glance. Performance: They are generally faster than standard for-loops for creating lists. Professional: It is a hallmark of "Pythonic" code—showing you really know the language! Mini Task Write a program that: Creates a list of numbers from 1 to 10. Uses List Comprehension to create a new list containing only the even numbers. Prints the resulting list. #Python #PythonLearning #50DaysOfPython #DailyCoding #LearnPython #CodingJourney #PythonForBeginners #LinkedInLearning #DeveloperCommunity
To view or add a comment, sign in
-
Explore related topics
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