Fullstack Development: Learning Python as JavaScript Developers
The Journey Begins
I have been working as a frontend developer for more than 8 years, and in the last 2 years, I decided to rethink my career and how I can grow. I found that frontend technology changes frequently: different frameworks, concepts, and the gap between React class components and hooks. I realized that all of this is just abstraction used to express business needs and personal vision. From this point, I decided to change my career path and become a full-stack developer slightly.
As we all know, frontend development is all about JavaScript nowadays, which is why I decided to learn Node.js and its main frameworks. All frontend developers encounter Node.js in one way or another, and as a Senior Frontend Developer, you should be able to write basic endpoints in Node.js with Express or another library. After 2 years of active development on the Node.js side, when my job became 50/50 between frontend and backend, I discovered that most projects don’t limit themselves to just one language.
Node.js is not the ideal tool for everything, especially when you’re working in a larger company. Different languages provide different solutions or are more optimal for solving specific business cases. This is why I started researching what I could learn as my second backend language and how I could utilize it in the future.
I want to share my experience and why I decided to stick with Python after trying to learn Rust (mostly not for web development), Swift (which is primarily a mobile-first solution), and Golang. Here, you’ll find out why I believe Python is a great opportunity for frontend developers to learn and how to start using it.
Why Python?
Nowadays, AI is something that everyone is talking about. Mentioning it in an interview as part of your experience always gives you extra points. Almost all companies are trying to incorporate AI into their products, and Python goes hand in hand with AI and Machine Learning. By learning Python, you not only gain the opportunity to write web applications with frameworks like Django, Flask, and FastAPI, but you can also start working with Machine Learning and AI services.
On one hand, learning more complex languages like Rust, Go, or Elixir is a good idea if you want to become a better programmer. However, from a career perspective, it's not an easy transition to becoming a backend developer with a completely different language that you're less familiar with.
Python is a dynamically typed programming language. As a JavaScript developer who has spent a significant part of your career in a similar environment, this shouldn't intimidate you, as you already know what kinds of issues to expect in the code.
With Python, you can not only start writing web applications but also leverage your skills in AI-related fields, which gives Python a significant advantage as a second language.
The Learning Curve
The learning curve was straightforward. In Python, you need to learn some basic concepts for sure. If you have experience with JavaScript it shouldn't be a big deal.
Here is the code example in Python:
import random def guess_the_number(): number_to_guess = random.randint(1, 100) attempts = 0 guessed = False print("Welcome to the Number Guessing Game!") print("I'm thinking of a number between 1 and 100. Can you guess what it is?") while not guessed: user_guess = int(input("Enter your guess: ")) attempts += 1 if user_guess < number_to_guess: print("Too low! Try again.") elif user_guess > number_to_guess: print("Too high! Try again.") else: print(f"Congratulations! You guessed the number {number_to_guess} in {attempts} attempts.") guessed = True guess_the_number()
I don’t think you’ll find anything too complex here. Even if you haven’t learned Python before, you can understand almost all the lines without reading the documentation.
The biggest difference you’ll notice is that Python uses indentation to define code blocks instead of curly braces. That might seem strange, and I still find it a bit unusual, but after a while, you get used to it, and reading code becomes easier.
Apart from that, many concepts in Python are similar to those in JavaScript. Instead of console.log, you can use print, and for string interpolation, you can add f at the beginning of the string and use almost the same syntax as in JavaScript.
Here is the JavaScript version of the code above:
function guessTheNumber() { const numberToGuess = Math.floor(Math.random() * 100) + 1; let attempts = 0; let guessed = false; console.log("Welcome to the Number Guessing Game!"); console.log("I'm thinking of a number between 1 and 100. Can you guess what it is?"); while (!guessed) { const userGuess = parseInt(prompt("Enter your guess: "), 10); attempts++; if (userGuess < numberToGuess) { console.log("Too low! Try again."); } else if (userGuess > numberToGuess) { console.log("Too high! Try again."); } else { console.log(`Congratulations! You guessed the number ${numberToGuess} in ${attempts} attempts.`); guessed = true; } } } guessTheNumber();
Overcoming Obstacles: Key Concepts
You can learn a lot of different concepts in Python. I showed the most confusing for me as a JavaScript developer.
Indentation-Based Syntax
As a JavaScript developer, you might be familiar with how to use code blocks with if/else and other operators. In most of the cases you just add {} and that’s it. Python's indentation-based system can be tricky.
Let’s see the JavaScript code:
if (role === "admin") { const posts = getDraftPosts() if (posts.length === 0) { throw NotFound() } return posts }
Python analog:
if role == "admin": posts = get_draft_posts() if posts.length == 0: raise NotFound() return posts
As you can see readability of blocks in Python could be challenging from the first view. This is why for me it was important to avoid deeply nested blocks because it is hard to read and easy to miss correct indention. Keep in mind that Python could attach your code to a wrong code block because of missed indention.
Type system
Python is a dynamic typing language but I was surprised to find Python built-in Types annotation.
def add(x: int, y: int) -> int: return x + y
You don’t need to install additional features, only what you need in Python *3.5 and above.*
Even more complex types could be described as equal to Typescript:
# enums from enum import Enum # import enum for built in lib class Season(Enum): # extend class to mark it as enum SPRING = 1 SUMMER = 2 AUTUMN = 3 WINTER = 4 print(Season.SPRING.name) # SPRING print(Season.SPRING.value) # 1 # or generics def first(container: List[T]) -> T: return container[0] list_two: List[int] = [1, 2, 3] print(first(list_two)) # 1
For using these types you are not required to install something or transpile this code. This is something I missed in JavaScript, at least Node.js. I know Node.js is adding some basic types in the nearest version (see Medium post about node.js built-in types support) but it looks poor now if you compare it with Python.
Python’s Global Interpreter Lock (GIL)
JavaScript uses an event-driven, non-blocking model, while Python's Global Interpreter Lock (GIL) can be a confusing concept in multi-threaded programs.
The Python Global Interpreter Lock (GIL) is a mechanism that ensures only one thread executes Python code at a time. Even if your Python program has multiple threads, only one thread can execute Python code at a time due to the GIL.
With JavaScript, you can achieve multithreading with web workers, but in Python, you need to use additional libraries to accomplish this.
A Pythonic Mindset
JavaScript's "multiple ways to do it" philosophy doesn't work as well in Python because Python adheres more closely to the concept "There should be one - and preferably only one - obvious way to do it."
In the JavaScript world, every company often creates its own code style guide, and it's fortunate if it follows basic JavaScript style recommendations. In reality, practices like using semicolons can vary widely, to the point where one project might use semicolons and another might not.
In Python, following Pythonic principles from PEP 8 (Python's style guide) is highly recommended. This guide outlines the basic rules of how to write Python code.
To write better code, it's essential to engage with the community and learn idiomatic Python practices that prioritize clarity and simplicity.
Managing Dependencies and Virtual Environments
This part might also be confusing. In JavaScript, you can usually add a package manager and start installing dependencies without any issues. However, Python’s pip and virtual environments may be new concepts.
In Python, when using additional dependencies, it’s highly recommended to use a separate virtual environment. Installing dependencies with pip (the Python equivalent of npm in JavaScript) in your environment could potentially break system utilities or the OS itself, as the system Python interpreter (the one that comes pre-installed with your operating system) is used by the OS and other system utilities.
As a solution, you can create a virtual environment with venv module:
python -m venv myenv myenv\Scripts\activate # for windows source myenv/bin/activate # for Mac
After you enter the virtual environment you can install all dependencies without any problem or danger for your root environment.
Finding Support and Resources
How I Learned Python
Learning a new language is always challenging. I started learning Python basics on an online platform, where I also completed some small projects. Here is the plan I used during my learning process:
- Python basics.
- Advanced Python concepts (module system, types, environment, async code).
- Learning the basics of the most popular frameworks like Django, Flask, and FastAPI.
- Writing my first API server with FastAPI.
- Adding a database and learning how to work with databases in Python.
- Deploying the application on a free hosting service.
Where to Find Help
You can find a lot of help in Reddit communities or Discord servers while learning. I’m mostly a Reddit user and would suggest finding subreddits for Python and the framework you decide to use for your first application.
Remember to use the official documentation. In my opinion, it looks overwhelming, and most of the time, I try to find related articles if I get stuck on a concept.
Make sure to read PEP 8 — Style Guide for Python Code, where you can find basic rules on how to write Python code.
Looking Back and Forward
As I reflect on my journey from a JavaScript developer to embracing Python, I have no regrets. This transition has opened up exciting opportunities, particularly in the realms of AI and machine learning, which I now leverage extensively in my projects, especially on the backend.
Looking ahead, the possibilities with Python are vast. Whether it's web development, data science, automation, or delving deeper into AI and machine learning, Python provides a powerful and versatile foundation to build on and explore new horizons.
The above is the detailed content of Fullstack Development: Learning Python as JavaScript Developers. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.
