Table of content:
Introduction
Ahoy, Code Explorers! Welcome aboard to learning series - 1 Lesson 2. As our ship sails through the binary seas of possibilities, we've reached the shores of a mystical island in the vast Pythonic ocean. But, dear sailors, this is no ordinary island; it's a haven for the bold, the creative, and those who dare to defy the echoes of the 'Hello World' tradition (pff... a greeting from the days of yore).
Gather 'round as we unfurl the sails of imagination and chart a course beyond the mundane. Cast away the worn-out greetings; let's forge a new code legend. Open your Python interpreter like a treasure chest, for we are about to embark on a cosmic journey that transcends the clichés of yesteryear.
No more 'Hello World,' but a resounding declaration to the universe awaits us. Brace yourselves as we code a greeting fit for the cosmic pioneers, the avant-garde developers who dare to whisper to the stars.
[If you have not installed your interpreter, I would suggest you to check out this guide:
In this inaugural lesson, we'll embark on an exciting journey through the fundamental building blocks of Python: Basic Syntax and Variables. Whether you're taking your very first steps into coding or brushing up on your Python skills, this series is crafted to make your learning experience enjoyable and rewarding.
Our First Program
In the vast expanse of code, we're not just saying 'Hello World'; today, we're reaching out to the cosmos and declaring, "Hello Universe!"
Just follow my lead, and let your code resonate with the universe:
Certainly! When we conjured `print("Hello Universe")` in the Python interpreter and hit Enter, it was like casting a spell:
1. Interpreter Awakens: Python woke up and listened.
2. Incantation Interpreted: It recognized the `print` spell (an in-built function).
3. Message Crafted: Our cosmic greeting was prepared.
4. Console Summoned: The interpreter called the console.
5. Celestial Display: The cosmic message materialized on the console.
In a nutshell, we used Python's magic to showcase our celestial proclamation on the coding stage! Good job explorers.
Let's dive deeper into learning , we learn more of the technical concepts.
Variables
Look at this code:
The output remains consistent—'Hello Universe'—but what unfolds behind the scenes speaks to the intricacies of memory management.
In Python, when we execute x = "Hello Universe"`, we're essentially creating a variable named 'x'. This variable acts as a container or label pointing to a specific location in the computer's memory where the string "Hello Universe" is stored.
This process involves two key steps:
1. Variable Creation:'x' is established as a variable, acting as a reference or label.
2. Memory Allocation:The string "Hello Universe" is stored in a designated memory location, and 'x' points to that location.
So, while the output remains constant, the distinction lies in the storage mechanism. The variable 'x' serves as a conduit, connecting us to the precise location in memory where our cosmic call to the universe resides. This insight into memory allocation is fundamental to understanding how Python manages and manipulates data.
Who is storing whom? In Python, a variable itself does not store data; instead, it acts as a label or reference to the location in memory where the data is stored. When you assign a value to a variable, you're essentially creating a reference to a specific memory address that holds the data.
Rules to choose your variable
myVar | Legal |
_myVar | Legal |
2myVar | Illegal (not allowed) |
my-Var | Illegal (not allowed) |
MYVAR | Legal |
my Var | Illegal (not allowed) |
False | Illegal (not allowed) |
Multiple Variable
Now you might have a pretty good idea that what is variable in python and how it works.
Do you want to work with more than one variable? Absolutely! Now that we've dipped our toes into the cosmic waters of Python variables, why stop at just one when we can orchestrate a symphony with more?
In the realm of expressions, we often find a solitary term on both sides – a lonely equation. But fear not, for in Python, we wield the power to assign not one, but a celestial duo or even a cosmic trio!
Now you must be wondering that what if both sides are not equal. When both sides of an expression aren't equal, Python raises the banner of error, asserting that a variable must be defined.Here it will be name 'z' is not defined.
Embarking on the cosmic journey of Python is not merely a spectator sport; it's a grand odyssey where you, the intrepid explorer, take the helm! To traverse the stars of Pythonic wisdom, you need more than just a gaze; you need hands-on practice, the key to unlocking the gates of excellence.
Brace yourselves, cosmic coders, for this is merely the prologue of our Pythonic saga! As we bid adieu to this celestial rendezvous, know that the cosmos of Pythonic wisdom awaits our exploration. The stars of basics will align, as we explore operators in the next chapter.
So, dear learners, let your coding sails catch the cosmic winds, stay attuned to the frequencies of knowledge, and together we shall embark on a journey where each line of code is a step toward mastery. Until then, let the stars be your guides, and may the Pythonic constellations light your path.
Link to next lesson
Stay tuned, keep learning and never be wasted.
Was the content helpful?
Yes
No
Needs improvement
Comentarios