DEV Community

Cover image for Basic Syntax of Python 3
Leandro Rodrigues Alexandre
Leandro Rodrigues Alexandre

Posted on

1 1

Basic Syntax of Python 3

Basic Syntax of Python 3

Python 3 is a high-level programming language known for its simple and readable syntax. Unlike other languages, Python uses indentation to define code blocks, making the code more organized and intuitive.

1. Key Features of Python Syntax:
Mandatory Indentation
Instead of curly braces {} or keywords like begin and end, Python uses indentation (spaces or tabs) to structure the code:
Image description

2. Variable Declaration
Python does not require explicit type declaration, as it is dynamically typed:
Image description

3. Comments
To write comments in Python, use # for single-line comments and ''' ''' or """ """ for multi-line comments:
Image description

4. Conditional Statements
Python uses if, elif, and else for control flow:
Image description

5. Loops
for and while loops are used for repeating code:
Image description

6. Functions
Functions in Python are defined using def:
Image description

✔ Variables store values, just like a box where we can keep different types of information, such as numbers, words, or even lists of items. Python automatically identifies the type of each value.
✔ Indentation organizes the code. Unlike other languages that use {} to define code blocks, Python uses spaces or tabs (indentation). This makes the code more readable and organized, but it must be used correctly.
✔ Conditionals (if, elif, else) help make decisions. Just like in real life, where we make choices based on conditions, Python uses if, elif, and else to execute different actions depending on the situation.
✔ Loops (for and while) allow repeating actions. When we need to execute a piece of code multiple times without rewriting it, we use loops. The for loop iterates over elements in a list or sequence, while while runs a block of code as long as a condition is true.
✔ Functions (def) help organize and reuse code. A function is a reusable block of code that we can call whenever needed, making programs more efficient and easier to maintain.

Sentry image

Make it make sense

Make sense of fixing your code with straight-forward application monitoring.

Start debugging →

Top comments (1)

Collapse
 
brunofamiliar profile image
Edson Bruno

Loved how you broke things down — Python’s simplicity really shines when explained like this! 🐍✨ This post feels like a warm welcome to anyone stepping into the Python world. Great job, Leandro! Can’t wait to see the next chapters of your journey. 🚀🧠

👋 Kindness is contagious

Value this insightful article and join the thriving DEV Community. Developers of every skill level are encouraged to contribute and expand our collective knowledge.

A simple “thank you” can uplift someone’s spirits. Leave your appreciation in the comments!

On DEV, exchanging expertise lightens our path and reinforces our bonds. Enjoyed the read? A quick note of thanks to the author means a lot.

Okay