print() and input() in Python — Two Functions. The Entire Conversation. Before loops, before functions, before data structures — any interactive program needs to solve two basic problems: how to send information to the user, and how to receive information from them. In Python, that’s where print() and input() come in. They’re the first two built-in functions the Helsinki MOOC introduces, and the reason is straightforward: without them, your program runs silently and alone. Nothing goes out, nothing comes in. print() handles output. It takes whatever you pass it and displays it in the terminal. That can be a string, a number, a variable, or a combination of all three: print("Current temperature:", temperature, "°C") Simple. But the moment you add it to your code, your program starts communicating. input() handles the other direction. It pauses the program, displays a message to the user, and waits. Whatever the user types is returned as a string that your program can then work with: city = input("Enter your city: ") One detail worth noting early: input() always returns a string, regardless of what the user types. If you ask for a number and plan to do arithmetic with it, you need to convert it explicitly. That’s not a flaw — it’s Python being precise about types, which is a habit worth developing from the start. Together, these two functions establish a pattern that scales across the entire language: programs receive data, process it, and return a result. print() and input() are just that pattern in its most direct form. Everything more complex is built on top of this. #Python #PythonMOOC2026 #BackendDevelopment #SoftwareEngineering #LearningInPublic #UniversityOfHelsinki
Andres Rios’ Post
More Relevant Posts
-
If you work with Python, have you ever wondered: • What is a list comprehension really? • Is it just a shorter for loop? • When should I NOT use it? List comprehensions are not just syntactic sugar, they are a fundamental part of writing Pythonic code. And no, they are not just “shorter loops”. They express intent. That’s the key difference. Let’s look at a simple example: 𝗿𝗲𝘀𝘂𝗹𝘁 = [] 𝗳𝗼𝗿 𝘅 𝗶𝗻 𝗿𝗮𝗻𝗴𝗲(𝟭𝟬): 𝗿𝗲𝘀𝘂𝗹𝘁.𝗮𝗽𝗽𝗲𝗻𝗱(𝘅 * 𝟮) Now, the same code using list comprehension: 𝗿𝗲𝘀𝘂𝗹𝘁 = [𝘅 * 𝟮 𝗳𝗼𝗿 𝘅 𝗶𝗻 𝗿𝗮𝗻𝗴𝗲(𝟭𝟬)] Both do the same thing. But they are NOT the same. When you write: 𝗿𝗲𝘀𝘂𝗹𝘁 = [𝘅 * 𝟮 𝗳𝗼𝗿 𝘅 𝗶𝗻 𝗿𝗮𝗻𝗴𝗲(𝟭𝟬)] You are telling Python: “I am building a new list from an existing iterable”. That intention is explicit. Now, here is where things go wrong: [𝗽𝗿𝗶𝗻𝘁(𝘅) 𝗳𝗼𝗿 𝘅 𝗶𝗻 𝗿𝗮𝗻𝗴𝗲(𝟭𝟬)] This works, but it should not be written like this. Why? Because list comprehensions are meant to create data, not perform side effects. When you use them like this, you are creating a list you don’t need, hiding the real intention of the code, and making it less readable. Takeaway: “List comprehensions are not about writing less code. They are about writing code that clearly expresses transformation.” Use them when you are building data. Avoid them when you are executing actions. #python #listcomprehension #pythonic
To view or add a comment, sign in
-
🚀 Day 4 of My Python Full-Stack Learning Journey Today I explored an important concept in Python: Type Conversion and Expressions. As beginners, we often work with different data types like int, float, string, and boolean. But what happens when we need to combine or convert them? That’s where Type Conversion comes into play. 🔹 Type Conversion Type conversion means changing one data type into another so Python can perform operations smoothly. Example: a = "10" b = 5 print(int(a) + b) # Output: 15 Here, the string "10" is converted into an integer using int() so the addition can happen. Some commonly used conversion functions in Python: ✔ int() → Converts value to integer ✔ float() → Converts value to decimal number ✔ str() → Converts value to string ✔ bool() → Converts value to True or False 🔹 Expressions in Python An expression is a combination of values, variables, and operators that Python evaluates to produce a result. Example: x = 10 y = 3 result = x + y * 2 print(result) # Output: 16 Python follows operator precedence, meaning multiplication happens before addition. Expressions can be: • Arithmetic Expressions • Logical Expressions • Comparison Expressions 💡 What I realized today: Understanding type conversion helps avoid type errors and makes our code more flexible. ❓ Questions for Developers: 1️⃣ What are some real-world scenarios where you frequently use type conversion in Python? 2️⃣ Do you prefer explicit conversion (int(), float()) or rely on automatic conversion in your code? I’m documenting my daily learning journey toward becoming a Python Full-Stack Developer. If you have tips, resources, or advice for beginners, feel free to share. 🙌 #Python #PythonLearning #CodingJourney #FullStackDeveloper #100DaysOfCode #LearnToCode #ProgrammingBasics #Developers #TechLearning #PythonBeginner #SoftwareDevelopment #FutureDeveloper #10000coders
To view or add a comment, sign in
-
F-strings in Python — Not Just Cleaner. Fundamentally Better. Python has had three ways to format strings over its history. If you’ve only learned the language recently, you might not have encountered the older two — but you will, because they still appear in legacy codebases, documentation, and tutorials written before Python 3.6. The first was % formatting, borrowed from C: name = "Andres" print("Hello, %s. You have %d messages." % (name, 5)) It works. But the syntax is cryptic, the order of arguments is error-prone, and it becomes harder to read as soon as you add more than one variable. The second was .format(), introduced in Python 3.0: print("Hello, {}. You have {} messages.".format(name, 5)) An improvement — more explicit, more flexible. But the variables and the placeholders are still separated. To understand what goes where, your eyes have to travel back and forth across the line. Then Python 3.6 introduced f-strings: print(f"Hello, {name}. You have {5} messages.") The variable lives inside the string, exactly where it appears in the output. No positional arguments. No external references. The code reads the way the sentence reads. Beyond readability, f-strings also evaluate expressions directly inline — which means you can do this: hours = 7.5 print(f"Weekly total: {hours * 5} hours") No intermediate variable needed. And in terms of performance, f-strings are consistently faster than .format() because they are parsed closer to compile-time rather than evaluated fully at runtime. Knowing all three methods matters. Understanding why f-strings became the standard tells you something about how Python evolves — always toward clarity. #Python #PythonMOOC2026 #BackendDevelopment #SoftwareEngineering #LearningInPublic #UniversityOfHelsinki
To view or add a comment, sign in
-
-
FUNDAMENTALS OF PYTHON It’s safe to say that Python fundamentals go far beyond just assigning variables or understanding iterations. ➠ Iteration, as the name implies, is the process of repeatedly executing a block of code using loops under specific conditions. From what I’ve learned so far: ➠ While loops handle indefinite iteration — they keep running as long as a condition remains true. ➠For loops handle definite iteratio — they run based on a sequence or a fixed range. Now here’s a real question: ➤ How many months do people spend learning functions, commands, operators, and loops… only to later call them “non-fundamentals”? Well… I’m that “someone.” And I moved past all of these about a week ago. Not because they don’t matter—but because this is my way of pushing myself forward and staying motivated for the journey ahead. To anyone on the same path as me: You’re doing well—but we can do even better. April 1st, 2026 marks the first draft on this journey. Hopefully, it won’t be the last. My Current Focus: Algorithm Building & Checking Right now, I’m diving into algorithm design and validation, which is honestly one of the most interesting parts of learning Python. It blends: ➼Basic algebra ➼ Binary thinking ➼Logical problem-solving The math itself is simple enough but improvisation using codes is where the fun begins ➤ First Concept: Guess-and-Check Algorithm (Also known as Exhaustive Enumeration) ➠ This algorithm works when: ➮ You can guess possible solutions, and ➮ You can **check if those guesses are correct** It keeps trying values until: ➮ A solution is found, or all possibilities are exhausted ➤ Simple Applications: ➠Finding square roots and cube roots of integers ➠Solving basic word problems ➠Building number guessing games and simple logic-based games This is just the beginning. More concepts, more challenges, more growth on the road to becoming a Python guru 🐍 Stay tuned. 👨💻👨💻
To view or add a comment, sign in
-
-
Syntax Errors and Tracebacks in Python: Learning to Read What the Language Is Telling You One of the first things that happens when you start writing Python is that things break. That is expected. What matters is what you do with the error message. Most beginners read the red text, feel a wave of anxiety, and start randomly changing things until the error disappears. That approach works occasionally and teaches nothing. The better habit, and the one the Helsinki MOOC encourages from the start, is to read the traceback carefully. A traceback is Python telling you exactly what went wrong and where. Take this example: Traceback (most recent call last): File "wages.py", line 5, in <module> print(daily_wages) NameError: name 'daily_wages' is not defined There are three things to extract here. The file and line number tell you where the program was executing when it failed. The last line tells you the type of error. The message after the colon tells you what specifically went wrong. The first rule worth knowing: read a traceback from the bottom up. The last line is always the most important one. It names the error type and gives the clearest description of the problem. The lines above it show the path the program took to get there. Error types are not arbitrary. A NameError means you referenced something that hasn't been defined. A TypeError means you tried to do something with a value that doesn't support it, like adding a string to an integer. A SyntaxError is different from both: Python catches it before the code even runs, which is why the traceback looks slightly different and shows no execution path. Understanding these distinctions changes how you approach a bug. A NameError tells you to look for a typo or a missing definition. A TypeError tells you to check what type of value a variable actually holds at that point. The error is not just a signal that something failed. It is a starting point for reasoning about why. The developers who debug fastest are not the ones who know the most. They are the ones who read the error before they start guessing. #Python #PythonMOOC2026 #BackendDevelopment #SoftwareEngineering #LearningInPublic #UniversityOfHelsinki
To view or add a comment, sign in
-
-
🚀 Day 6: Mastering the Logic of Python | Flow Control Python isn't just about writing code; it's about making decisions. Today was all about Flow Control Statements—the "logical backbone" that transforms a script into an intelligent program. In my latest session, I dived deep into how Python decides how and when code blocks execute. Here’s a breakdown of the Day 6 deep dive: 🧠 The Decision Engine: Conditional Statements I explored how to guide program execution through branching paths: if, if-else, and if-elif-else: Handling everything from simple checks to complex, multi-layered grading systems. match-case (Python 3.10+): A cleaner, more readable "multi-way" decision-maker that feels like a modern switch-case. 🔄 The Engine of Efficiency: Looping Statements Iteration is where the power lies. I practiced: for & while loops: Repeating operations until conditions are met. Loop-Else: A unique Python feature where the else block executes only if the loop finishes normally (without a break). Nested Loops: Essential for processing complex data like matrices and patterns. 🚦 Fine-Tuning Control: Transfer Statements Knowing when to exit or skip is just as important as knowing when to run: break: Immediate exit from a loop. continue: Skipping the current iteration to move to the next. pass: The ultimate "placeholder" that does nothing but keep the syntax valid. 🛠️ Hands-On Logic Building I applied these concepts to solve real-world logic problems: ✅ Finding the biggest of three numbers using nested if..else. ✅ Building a Digit-to-Word converter. ✅ Mathematical validation: Prime Number and Perfect Number checks. ✅ String Reversal logic using both for and while loops. A huge shoutout to my mentor Nallagoni Omkar Sir for emphasizing that it's not just about syntax—it's about clarity, edge cases, and real-world logic. Next Stop: Functions! 🚀 #Python #CorePython #FlowControl #DataScience #LearningInPublic #CodingJourney #PythonProgramming #LogicBuilding #TechCommunity
To view or add a comment, sign in
-
List comprehensions are one of those Python features that look intimidating at first and then become second nature fast. New tutorial on PythonCodeCrack walks through everything from the ground up: — The three-part syntax and what each part does — How a comprehension maps to an equivalent for loop — Adding filter conditions — Using enumerate() and zip() as source iterables — Ternary expressions vs. filter conditions (a common point of confusion) — When not to use a comprehension — How CPython executes them differently from for loops, including what changed in Python 3.12 — Dict and set comprehensions Includes an interactive syntax visualizer, step tracer, spot-the-bug challenges, quizzes, and a final exam with a certificate of completion. https://lnkd.in/g6VisquH #python #FreeCertificationCourse #tutorials
To view or add a comment, sign in
-
Python: 05 🐍 Python Iterables: Diving Deeper 🚀 We'll work on different complex types (range, list etc.) and strings iteration. We've already known the for loops, now let's dive into deeper and know what is range function returns. 🔍 We will use a built in 'type' function to get the type of an object. 🛠️ For example: type(5) .. it will return <class 'int'>; that means number 5 is an integer value 🔢 type(range(5)) .. it will return <class 'range'>; that means we get the value from a range function that means its an object of type range! 🧊 Primitive vs. Complex Types 💡 In python we have primitive types like numbers, strings, Booleans. We also have so many complex types, 'range' is one of those complex types. So interesting concept of range is, it is iterable which means we can iterate over it or use it in a for loop. That is why we can write code like this: for x in range(3): Here x can hold number in the range in each iteration. 🔄 Result: 1 2 3 Strings are also iterable! 🧵 For example: for x in "python": print(x) It will return: ✨ p ✨ y ✨ t ✨ h ✨ o ✨ n Which means x will hold one character from the string in each iteration. 🔡 List Iteration 📋: for x in [1, 2, 3, 4,..,n]: print(x) It will return: 1 2 3 4 ... ... ... nth X will hold one object from the list in each iteration. 🎯 #PythonProgramming #PythonDeveloper #Coding #python #iterator #DataScience #pythondeveloper #programmer
To view or add a comment, sign in
-
-
💡 Why does this Python code fail? 🤔 >>> 1name = "Python" Error. But why? --- Because Python has rules for naming variables. These names are called "identifiers" 👇 --- ✔ Valid: name = "Python" _age = 20 ❌ Invalid: 1name = "Python" my-name = "Python" --- 💡 Quick Rules: • Must start with a letter or _ • Cannot start with a number • No spaces or special symbols (-, @, etc.) • Cannot use keywords (like if, for, class) --- Simple idea: Identifiers = names for variables --- Once you know this, you’ll avoid many small errors ⚡ Have you ever faced this issue? 👇 #Python #Coding #Programming #Beginners #LearnInPublic
To view or add a comment, sign in
-
-
yield is one of those Python keywords that looks simple until someone asks you to explain it. Most developers can tell you a function with yield in it produces values and works in for loops. Fewer can explain why that same function doesn't actually run when you call it. Turns out, that's the whole point. Generators (functions with yield) are functions that pause mid-execution and resume exactly where they left off: local variables, loop counters, everything intact. In my Python Context Managers series, I'm covering generators as a dedicated article because they are not a standalone concept. They are the engine behind @contextmanager, a cleaner way to build context managers in Python. You can't fully understand one without understanding the other. This article is a deep dive into generator functions: https://lnkd.in/dSNegaWK A function that remembers where it left off changes everything. #Python #SoftwareEngineering #Backend #Programming #WebDevelopment #BuildBreakLearn
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