This content originally appeared on DEV Community and was authored by Azim Annayev
Introduction
Ever wonder why Python is the second go-to language for so many programmers? Because it’s literally everywhere.
Python is used in web development, data science, machine learning, automation, and even artificial intelligence. But what is most appealing — especially for new developers — is how readable it is. The syntax is simple, the learning curve isn’t so rough, and some people even joke that it feels like writing in plain English.
I started learning JavaScript about ten months ago. Once I honed my fundamentals in JavaScript, I wanted to learn a language that would open more doors and expand my horizon in tech beyond web development. Python kept coming up in conversations — not just because it’s powerful, but because people actually enjoy using it.
Syntax
Indentation and Variables
Right off the bat, two things will blow your mind about Python — especially if you’re coming from JavaScript.
First, Python uses indentation (whitespace) to define code blocks, rather than curly braces {}
like in JavaScript and many other languages. That means spacing of your code is very important.
# Python
if True:
print("I love programming!")
Compare that to JavaScript:
// JavaScript
if (true) {
console.log("I love programming!")
}
In Python, there’s no need for {}
— the indentation is the structure.
Another surprising quirk is how variables are declared. Python doesn’t require keywords like let
, const
, or var
. You just write the variable name and assign a value.
# Python
name = "Azim"
age = 16
// JavaScript
let name = "Azim";
const age = 16;
There’s no need to specify types or use extra keywords — Python figures it out for you.
Lists and Tuples
Lists in Python are similar to arrays in JavaScript — they can hold multiple values, are ordered, and are mutable (you can change them).
They have a very similar syntax, except that:
- Python typically uses snake_case to declare variables and JavaScript uses camelCasing.
# Python
my_list = [2, 4, 6, 8]
// JavaScript
const myList = [1, 3, 5, 7];
Python also introduces another built-in data structure called Tuples. At first glance, tuples look a lot like lists — they can store an ordered collection of elements — but they come with a few key differences:
- Tuples are immutable — meaning once created, their values cannot be changed.
- More memory-efficient and faster than lists, especially for large, fixed data sets.
# A tuple of mixed data types
my_tuple = ("azim", 234, "joshua", 314, 245)
# A single-element tuple
my_tuple = ("andrey",)
Without the comma, Python will treat it as a plain string or number.
Python has a useful set of built-in methods you can use on lists and tuples. List methods such as append()
, sort()
, clear()
, remove()
, reverse()
, etc., allow efficient ways to manipulate and interact with data.
my_friends = ["Vasya", "Bob", "Juan"]
my_friends.append("Jordi")
print(my_friends) # ["Vasya", "Bob", "Juan", "Jordi"]
Tuples can also be used in real-world scenarios like coordinates or color values – places where you need fixed, unchanging data:
# A tuple representing RGB color
rgb_color = (255, 0, 127)
# A tuple for a geographical coordinate (latitude, longitude)
location = (40.7128, -74.0060)
Read more about List Methods here.
Tuples have fewer methods: mainly .index()
and .count()
.
my_fruits = ("orange", 234, 567, "grape", "watermelon")
print(my_fruits.index("orange")) # 0
print(my_fruits.index(567)) # 2
my_fruits = ("apple", "apple", 2, 3, 4)
print(my_fruits.count("apple")) # 2
print(my_fruits.count(3)) # 1
Conditional Statements and Logical Operators
Python uses if/elif/else
to handle conditional logic.
number = 0
if number > 0:
print("The number is positive.")
elif number == 0:
print("The number is zero.")
else:
print("The number is negative.")
JavaScript equivalent:
const number = 0;
if (number > 0) {
console.log("The number is positive.");
} else if (number === 0) {
console.log("The number is zero.");
} else {
console.log("The number is negative.");
}
Logical operators in Python:
-
and
means both conditions must be true. -
or
means at least one must be true. -
not
inverts the truth value.
number = 5
if number > 0 and number < 10:
print("Positive and less than 10")
elif number < 0 or number > 100:
print("Negative or very large")
elif not number == 5:
print("Not equal to 5")
else:
print("Exactly 5")
let number = 5;
if (number > 0 && number < 10) {
console.log("Positive and less than 10");
} else if (number < 0 || number > 100) {
console.log("Negative or very large");
} else if (!(number === 5)) {
console.log("Not equal to 5");
} else {
console.log("Exactly 5");
}
For Loop and List Comprehension
Python’s for
loops are super clean:
my_list = [1, 2, 3, 4]
for num in my_list:
print(num)
Versus JavaScript:
const myList = [1, 2, 3, 4];
for (let i = 0; i < myList.length; i++) {
console.log(myList[i]);
}
List comprehensions let you build lists in a single line:
squares = [x**2 for x in range(5)]
print(squares) # [0, 1, 4, 9, 16]
Try it yourself: Write a list comprehension that returns all even numbers from 0 to 20.
Functions and Lambda Functions
Python functions use the def
keyword:
def greet(name):
return f"Hello, {name}!" # f-string syntax
print(greet("Azim"))
JavaScript comparison:
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet("Azim"));
Lambda functions are one-liner anonymous functions:
square = lambda x: x * x
print(square(5)) # 25
JavaScript equivalent:
const square = (x) => x * x;
console.log(square(5));
You’ll often see lambdas used in sorting, mapping, or filtering lists.
names = ["bob", "alice", "jane"]
names.sort(key=lambda x: len(x))
print(names) # ['bob', 'jane', 'alice']
What Python Doesn’t Do
While Python has a lot going for it — especially its simplicity and readability — it’s not without tradeoffs.
For example:
- Python tends to run slower than JavaScript in browser-based environments.
- It’s not the best fit for mobile app development.
- And because it’s dynamically typed, it can lead to unexpected bugs if you’re not careful with types.
But in many cases, these drawbacks are outweighed by Python’s ease of use, massive ecosystem, and wide range of applications — especially in data science and automation.
As with any language, it’s about choosing the right tool for the job.
Final Thoughts
This blog isn’t meant to cover everything about Python — instead, it’s a reflection of what stood out to me as a JavaScript developer learning Python for the first time. These are the things I found quirky, interesting, and surprisingly smooth to work with — like list comprehensions, lambda functions, and Python’s indentation-based style.
There’s still so much more to explore in Python: Modules, Dictionaries, Classes and Object-Oriented Programming, File handling, Error handling… the list goes on.
I’m still learning, and I plan to write more as I go deeper. But if you’re curious and want to keep exploring, here are some awesome resources that have helped me:
Official Python Docs — The most accurate and comprehensive reference for Python syntax, features, and standard library modules. A bit dense, but essential for in-depth learning.
freeCodeCamp Python Curriculum — Hands-on, project-based lessons that walk you through real Python use cases. Great for staying motivated.
W3Schools Python Tutorial — Simple and beginner-friendly with lots of bite-sized code examples. Perfect for quick lookups.
Codecademy Python Course — Interactive lessons with a built-in coding environment. Excellent if you prefer to learn by doing.
Corey Schafer’s YouTube Channel — High-quality, no-nonsense video tutorials on everything from the basics to advanced topics like decorators and Flask.
Thanks for reading — and if you’re learning Python too, I’d love to hear what surprised or confused you the most. Let’s keep building and getting better together!
This content originally appeared on DEV Community and was authored by Azim Annayev