Table Of Contents
- Introduction
- Popularity
- Variables
- Outputs
- Comments
- Conditional statements
- Functions
- Loops
- Reflections
- Conclusion
Introduction
Learning a new language can be difficult. I've been learning Python on my own, and it has been an exciting and challenging adventure. The most challenging aspects have been maintaining accountability and finding inspiration, particularly when things seem to be moving slowly. But every small accomplishment, like as figuring out how loops work or making a function work, has motivated me to keep continuing.
Popularity
Python is currently the most widely used programming language in the employment market. It has held the top spot on the TIOBE Index since last year. Its simplicity, adaptability, and popularity make it a must-know language for growing developers.
What drew me to study Python was its clear and concise syntax and its similarity to JavaScript. Additionally, its versatility allows developers to seamlessly transition between different types of projects, from web development to data analysis. Its power when it comes to web development and using frameworks like Django are essential for a web developer such as myself.
Variables
In JavaScript, we use const, let, or var to declare variables. For example:
const greeting = "Hello";
let name = “America”
name = “Clove”
console.log(name) => “Clove”
-
const
variables are immutable unless they hold arrays or objects. -
let
variables are mutable and can be reassigned. -
var
is an older version of declaring variables.
Var
is function-scoped instead of block-scoped which can cause errors and confusion such as hoisting. In modern Javascript, it is uncommon and discouraged from being used. const
and let
are the preferred variables to use.
In Python, variables are declared by assigning a value to a unique name. If you want to indicate a constant, you should name the variable in all uppercase letters, like this:
greeting = "Good morning"
MY_NAME = "America"
However, unlike JavaScript, Python doesn’t enforce immutability for constants. This means even if you name a variable in all caps to signify it shouldn’t change, Python will allow you to reassign it without any error or warning. This is an important difference from JavaScript because it illustrates the importance of developer discipline and conventions in Python.
Displaying Outputs
In JavaScript, we use console.log()
to display output in the terminal. For example:
console.log('Hello');
In Python, we use the print()
function instead:
print('Hello')
Displaying outputs is essential for a coder. It helps debug and understand what your code is doing at certain points in the code.
Conditional statements
Conditional statements in JavaScript include if
, else if
, and else
. Code blocks are determined using the curly braces. For example:
if (x > 0) {
console.log("Positive");
} else {
console.log("Non-positive");
}
In Python, conditional statements using if
, elif
, and else
with indentation are required to define blocks. Unlike Javascript, Python does not have curly braces to help determine a block.
if x > 0:
print("Positive")
else:
print("Non-positive")
Key Difference:
In Python, indentation is important for the code to run correctly. It helps the system understand where there is a block of code. Improper indentation will result in errors. While Javascript, use the curly braces to determine the block of codes.
Functions
In JavaScript, we define functions using the function
keyword or arrow functions:
function greet() {
console.log("Hello");
}
const greet = () => {
console.log("Hello");
};
In Python, functions are defined using the def
keyword:
def greet():
print("Hello")
Loops
JavaScript offers for
, for...of
, and while
loops for iteration:
for (let i = 0; i < 5; i++) {
console.log(i);
}
Explanation:
The for
loop iterates from 0 to 4. To create a for
loop, we must initialize i to a starting value (in this case, 0). We create a condition (i < 5) to determine if the loop should continue running. If i is less than 5, the loop executes. Finally, i++ increments i by 1 after each iteration. This loop prints the numbers 0 to 4.
In Python, we use for
and while
loops, but for
loops are often used with iterators:
for i in range(5):
print(i)
Explanation:
The range(5)
function generates numbers from 0 to 4, similar to the JavaScript loop above. Creating a for loop in Python is simpler because range()
handles the sequence generation for us. The range()
function can be used with three parameters: range(start, stop, step).
- start (optional): Specifies where the loop begins. Defaults to 0 if not provided.
- stop: Determines where the loop stops (exclusive).
- step (optional): Specifies the incrementation. Defaults to 1 if not provided.
Reflection
Staying accountable was a challenge. Balancing my responsibilities has been difficult as I’ve been juggling helping my dad with his business, assisting my mom with household chores, and making time for myself and my friends. At times, I felt overwhelmed trying to keep everything in order while still giving myself time to learn Python.
To overcome these challenges, I’ve started developing schedules and experimenting with different planning methods to stay organized. I found paper planners work better for me than digital ones, as they help me stay focused and feel more confident. I also improved the way I take notes by using tools like Notion, which help me have clear and assessable notes. Additionally, having support from my instructors has been invaluable—they help keep me accountable and encourage me to stay on track despite the obstacles.
These strategies haven’t made the challenges disappear, but they’ve helped me manage my time better and maintain progress in learning Python.
Conclusion
Throughout this guide, I've discussed the fundamentals of Python and how it relates to JavaScript. By studying variables, outputs, conditional statements, functions, and loops, I hope to give beginners a solid foundation for learning how to code in Python.
Several materials proved useful during my study path. I subscribed to BroCode's YouTube channel, which features short and simple videos. The 1-hour Python training and beginner-friendly project tutorials were especially helpful in practicing Python concepts. In addition, I found Codecademy's Learn Python 3 course to be an amazing introduction to Python from scratch.
Finally, developing a learning timetable helped me stay focused and accountable. By organizing my days, I was able to make progress while balancing my other responsibilities. I encourage you to find tools that work for you! Something I like to remind myself is every step counts, no matter how big or small.
Great resources to check out :
Learn Python3
YouTube (1 hour) tutorial
YouTube tutorials on how to build small-scale projects:
Creating a schedule
Good luck everyone!
Top comments (0)