𝗣𝘆𝘁𝗵𝗼𝗻 𝗘𝘀𝘀𝗲𝗻𝘁𝗶𝗮𝗹𝘀 𝗳𝗼𝗿 𝗚𝗲𝗻𝗔𝗜

You know JavaScript and TypeScript. Now you want to build with LangChain and GenAI tools. You need Python.

You do not need to start from scratch. You can map Python concepts to what you already know.

Here is a quick translation guide for JS developers:

Core Syntax

  • Variables: Use simple assignment. For constants, use UPPER_CASE.
  • Booleans: Use True and False (they are capitalized).
  • Null/Undefined: Use None.
  • Printing: Use print() instead of console.log().
  • Template Literals: Use f-strings like f"Hello, {name}".

Logic and Flow

  • Indentation: Python uses whitespace instead of curly braces {}. This is the most important change.
  • Truthy/Falsy: In JS, an empty array [] is truthy. In Python, an empty list [] is falsy.
  • Comparison: Python's == compares values like JS ===.

Data Structures

  • Lists: Similar to Arrays. Use .append() instead of .push().
  • Dictionaries: Similar to Objects. Use person["name"] to access values.
  • Tuples: Like frozen arrays. You cannot change them after creation.
  • Sets: Use these for unique items and math operations like intersections.

Functional Patterns

  • Map and Filter: Use list comprehensions instead of .map() and .filter().
  • Example: [n * 2 for n in numbers] replaces numbers.map(n => n * 2).
  • Destructuring: Use unpacking to assign multiple variables at once.

Modern GenAI Essentials

  • Pydantic: This is critical. LangChain uses Pydantic for data validation and structured outputs.
  • Decorators: These work like Higher-Order Components in React. They wrap functions to add logic.
  • Async: Python uses async and await just like JS. Use asyncio.gather() instead of Promise.all().
  • Generators: These allow you to stream LLM tokens one by one.

Package Management

  • npm is pip.
  • node_modules is .venv.
  • package.json is requirements.txt.

Always use a virtual environment (.venv) to keep your projects clean.

Source: https://dev.to/ajmal_hasan/python-essentials-for-genai-lji