codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🐍

Python Programming

3 / 68 topics
1Python Introduction & Features2Python Get Started & VirtualEnv3Python Syntax & First Program4Python Comments & Keywords5Python Variables & Constants6Python Basic Input and Output
Tutorials/Python Programming/Python Syntax & First Program
🐍Python Programming

Python Syntax & First Program

Updated 2026-05-15
15 min read

Python Syntax & First Program

Introduction

Welcome to the third topic in our Python journey! In this tutorial, we will dive into the fundamental syntax rules of Python. Understanding these rules is crucial as they form the building blocks for writing clear and error-free code. We'll cover indentation, case sensitivity, line continuation, and finally, how to write your very first complete Python program.

Core Content

Indentation

Python uses indentation to define the scope in the code. Unlike languages that use curly braces {} or keywords like begin/end, Python relies on consistent indentation (usually 4 spaces) to group statements. This rule is enforced by the Python interpreter, and not following it will result in a syntax error.

Example:

indentation.py
1if True:
2 print("This is indented")
3print("This is not indented")
Terminal
Output
10
20

Best Practice: Use a consistent naming convention to avoid confusion. For variables and functions, use snake_case, and for classes, use PascalCase.

Line Continuation

Python allows you to continue long statements over multiple lines using parentheses (), brackets [], or braces {}. This is particularly useful when dealing with complex expressions.

Example:

line_continuation.py
1total = (1 + 2 +
2 3 + 4)
3print(total) # Output: 10
Terminal
Output
The sum of 5 and 3 is 8

Explanation:

  • We define two variables num1 and num2 with values 5 and 3, respectively.
  • We calculate their sum and store it in the variable sum.
  • Finally, we print the result using the print() function.

Practical Example

Let's expand our first program to include user input. The program will ask the user for two numbers and then display their sum.

Example:

practical_example.py
1# This is a simple calculator program with user input
2num1 = float(input("Enter the first number: "))
3num2 = float(input("Enter the second number: "))
4
5# Adding two numbers
6sum = num1 + num2
7
8# Printing the result
9print("The sum of", num1, "and", num2, "is", sum)
Terminal
$ python3 practical_example.py
Enter the first number: 7.5
Enter the second number: 4.2
The sum of 7.5 and 4.2 is 11.7
Output
The sum of 7.5 and 4.2 is 11.7

Explanation:

  • We use the input() function to get user input, which returns a string by default.
  • We convert the input to a float using float() so that we can perform arithmetic operations.
  • The rest of the program remains the same as our first example.

Summary

ConceptDescription
IndentationPython uses indentation (4 spaces) to define code blocks.
Case SensitivityPython is case-sensitive; variable names with different cases are distinct.
Line ContinuationStatements can be continued over multiple lines using parentheses, brackets, or braces.
First ProgramA simple calculator program that adds two numbers and prints the result.

What's Next?

Now that you have a solid understanding of Python syntax and how to write your first program, it's time to explore comments and keywords in Python. In the next topic, we'll learn about different types of comments and reserved words in Python, which will help you write more readable and structured code.

Stay tuned for the next tutorial!


PreviousPython Get Started & VirtualEnvNext Python Comments & Keywords

Recommended Gear

Python Get Started & VirtualEnvPython Comments & Keywords