Python Syntax

JK 2010 
Created at
Updated at  
7,380 0 0

Execute Python Syntax

As we learned in the previous page, Python syntax can be executed by writing directly in the Command Line:

>>> print("Hello, World!")
Hello, World!

Or by creating a python file on the server, using the .py file extension, and running it in the Command Line:

C:\Users\Your Name>python myfile.py

Python Indentation

Indentation refers to the spaces at the beginning of a code line.

Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important.

Python uses indentation to indicate a block of code.

if 5 > 2:
  print("Five is greater than two!")

Below Python code will give you an error, because you skip the indentation:

if 5 > 2:
print("Five is greater than two!")

The number of spaces is up to you as a programmer, the most common use is four, but it has to be at least one.

if 5 > 2:
 print("Five is greater than two!") 
if 5 > 2:
        print("Five is greater than two!") 

You have to use the same number of spaces in the same block of code, otherwise Python will give you an error:

if 5 > 2:
 print("Five is greater than two!")
        print("Five is greater than two!")

Python Variables

In Python, variables are created when you assign a value to it:

x = 5
y = "Hello, World!"

Comments

Python has commenting capability for the purpose of in-code documentation.

Comments start with a #, and Python will render the rest of the line as a comment:

#This is a comment.
print("Hello, World!")

 

Tags Python Python Comments Python Syntax Python Variables Facebook X
Comments 0
Similar posts
  1. Python Comments
    7,492
  2. Python Variables
    7,356
  3. Python Getting Started
    7,417
  4. Python Introduction
    7,076
  5. What is Python?
    7,675
  6. Python Data Types
    7,401
  7. Python String Operations
    7,374
  8. Python Lists
    7,305
  9. String concatenation by join()
    7,109
  10. Printing string n times
    7,045
  11. Python Arithmetic Operators
    7,054
  12. Python Comparison Operators
    7,218
  13. Python Tuples
    7,142
  14. Python Sets
    7,068
  15. Python Dictionaries
    7,031
  16. Python Conditions and If statements
    7,111
  17. Python While Loops/For Loops
    7,460
  18. Python Functions
    7,046
  19. Python Lambda
    7,085
  20. Python Arrays
    7,064
  21. Python Classes/Objects
    7,421
  22. Python Inheritance
    7,170
  23. Python Iterators
    7,082
  24. Python Polymorphism
    7,061
  25. Python Scope
    7,041
  26. Python Modules
    7,069
  27. Code Chronicles - A Caffeine-Fueled Journey into Data Software Engineering
    7,333
  28. Machine Learning Types and Programming Languages
    7,205
  29. Python Tutorials for AP Computer Science Principles, Data Projects and High School Internship
    7,833
  30. Mastering Excel Data Manipulation with Python
    7,044
  31. Challenge: One Code Problem Per Day
    1,037
  32. Clean Python Environments: The Power of venv vs. Docker
    759
  1. Python Functions
    7,046
  2. Python While Loops/For Loops
    7,460
  3. Python Conditions and If statements
    7,111
  4. Python Dictionaries
    7,031
  5. Python Sets
    7,068
  6. Python Tuples
    7,142
  7. Python Comparison Operators
    7,218
  8. Python Arithmetic Operators
    7,054
  9. Printing string n times
    7,045
  10. String concatenation by join()
    7,109
  11. Python Lists
    7,305
  12. Python String Operations
    7,374
  13. Python Data Types
    7,401
  14. Python Variables
    7,356
  15. Python Comments
    7,492
  16. Python Getting Started
    7,417
  17. Python Introduction
    7,076
  18. What is Python?
    7,675
Recently updated
  1. Bootstrap vs. Tailwind CSS: Origins, Features, Pros & Cons, and How to Choose the Right Framework
    41
  2. The Complete Guide to Golang: History, Features, Real-World Uses, and Code Examples
    101
  3. Telemetry vs. Analytics: Understanding the Difference and Why It Matters
    166
  4. The Evolution and Production Reality of Agentic AI
    161
  5. How to Activate or Waive Your UIUC Student Health Insurance
    237
  6. Complete Guide to Building a Machine Learning Model
    281
  7. My life cuts at Las Vegas during Thanksgiving day holiday
    7,362
  8. The Cybercab Transformation: From Autonomous Taxi to Mobile Base Station
    309
  9. Harness vs. OpenClaw: Two Very Different "Agents"
    891
  10. Clean Python Environments: The Power of venv vs. Docker
    759
  11. What is Docker? Why is Docker also useful in a development environment?
    578
  12. UIUC 2026-2027 Academic Calendar
    1,454
  13. How to Build Llama 3 AI Apps with Python: Setup & User Prompts
    759
  14. Open-Source LLMs: The AI Revolution
    705
  15. Resume 2.0: Leveling Up for My First Software Gig
    2,068
  16. Not everyone will understand what this man just did
    1,720
  17. UIUC Dorm Guide: Find Your Perfect Fit !!
    1,543
  18. Unpacking IU's Shopper
    704
  19. Jackie Chan's Police Story: The Action Masterpiece
    602
  20. The IVE Story: Identity, 'I AM' Charts, and Influence
    906
  21. Tech Visionaries who graduated at UIUC - You are the Next Turn
    1,146
  22. Open Databases for Sex Crime Occurrences in the U.S.
    673
  23. Automatically copy text to the clipboard when dragging the mouse in the Cursor
    2,508
  24. My First Day at University of Illinois-Urvana Champaign
    1,154
  25. Sand, Sea, and a Splash of Fun at Newport Beach: A Family Adventure
    8,081
  26. Sun, Rocks, and Adventure: A Day at Joshua Tree National Park
    8,153
  27. Sipping the Stars: My Starbucks Adventure
    9,568
  28. Exciting explore at Sequoia National Park
    7,613
  29. My Life Shot at Death Valley
    1,621
  30. Ip Man fights with Muay Thai Master
    898
  31. Mad Clown - Don't Die
    971
  32. How to get Student Enrollment and Degree Verification at UIUC
    4,642
  33. LAX Thanksgiving Rush: A Joyful Reunion
    893
  34. ZO ZAZZ(조째즈) - Don`t you know (모르시나요) (PROD.ROCOBERRY)
    1,077
  35. FISHINGIRLS Unleashes Energetic EP 'Funiverse' Featuring Signature Track 'Fishing King'
    938
  36. 10CM - To Reach You (너에게 닿기를)
    1,124
  37. Feeling weak? Transform yourself at the UIUC ARC!
    1,545
  38. BOYNEXTDOOR - If I Say I Love You
    1,152
  39. The Future of Software Engineer - AI Engineering
    912
  40. G Dragon x Taeyang (Eyes Nose Lips, Power, Home Sweet Home, GOOD BOY) - LE GALA PIÈCES JAUNES 2025
    876
  41. Lie - Legend song by BIGBANG
    7,786
  42. Why ROLLBACK is useful when you work with Google Gemini CLI?
    804
  43. Reimbursement after Vaccination at McKinley Health Center
    970
  44. Gemini CLI makes a Magic! Time to speed up your app development with Google Gemini CLI!
    936
  45. Common Questions from UIUC school life in terms of CS Program
    1,068
  46. UIUC Immunization Compliance
    1,164
  47. LEE CHANHYUK's songs really resonate with my soul - Time Stop! Vivid LaLa Love, Eve, Endangered Love ...
    1,062
  48. LEE CHANHYUK - Endangered Love (멸종위기사랑)
    1,064
  49. Cupid (OT4/Twin Ver.) - LIVE IN STUDIO | FIFTY FIFTY (피프티피프티)
    842
  50. Common methods to improve coding skills
    957