Python Syntax and Basic Output

📘 Python 👁 105 views 📅 Nov 05, 2025
⏱ Estimated reading time: 2 min

Python Syntax and Basic Output

Python is a high-level, interpreted language known for its simplicity and readability. Understanding syntax and output is essential for all Python programs.


1. Python Syntax Rules

  • Python uses indentation instead of braces {} to define code blocks.

  • Statements end automatically at newline; no semicolons needed (optional).

  • Python is case-sensitive: Variable and variable are different.

  • Comments start with # for single-line comments, or ''' ''' / """ """ for multi-line comments.

# Single-line comment """ Multi-line comment explaining code """

2. Python Statements

  • Single-line statement:

x = 5 print(x)
  • Multiple statements on a single line (use ;):

a = 1; b = 2; c = a + b print(c)

3. Indentation

  • Indentation is mandatory for defining blocks like loops, conditionals, and functions.

if True: print("This is indented correctly") # Wrong indentation will cause IndentationError

4. Python Output Using print()

  • print() displays information to the console.

# Simple output print("Hello, Python!") # Printing variables name = "Alice" age = 25 print(name, age) # Formatted output (f-strings) print(f"My name is {name} and I am {age} years old.") # Using separator and end print("Python", "is", "fun", sep="-", end="!\n") # Output: Python-is-fun!

5. Escape Characters

Escape SequenceMeaning
\nNew line
\tTab
\\Backslash
\'Single quote
\"Double quote
print("Hello\nPython") # Hello (new line) Python print("Column1\tColumn2") # Tab space

6. Key Points

  • Python emphasizes readability and simplicity.

  • Indentation defines code blocks.

  • print() is used for basic output, supports variables, formatting, and escape sequences.

  • Python statements can span multiple lines using backslash \ if needed.

  • Proper syntax is crucial to avoid runtime errors.


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes