Categories: python

Python Syntax Rules & Hello World Program

Python Syntax Rules:

Here are a few things you should know beforehand:

  • Python is case-sensitive, which means, for example, Name and name have different meanings
  • The standard is to use English names in programming
  • All variables should start with a lowercase letter, for example, var = 4
  • Functions begin with lowercase
  • Classes begin with a capital letter
  • There is no command terminator, which means no semicolon “;” or anything.
  • Single quotes ‘ ‘, double quotes “” and even triple quotes ”’ “”” can be used to represent string literals.
  • In Python, you can include comments in your code by beginning them with a #.
  • To write multiline code that does not confuse the Python interpreter, use a backslash at the end of each line to explicitly denote line continuation.
  • Python doesn’t use brackets, therefore code indentation is required
Hello World Program:
print ("Hello, World!")
  • Write and run this code in IDLE, or you can save it in a python code file called test.py (you can name it anything, just keep the extension of the file as .py).
  • Run the test.py python script, open IDLE, use the cd command to navigate to the directory where you saved the file, and then type the following in command prompt or your terminal:
python test.py
Output:
Hello, World!

Note: also read about Python 2 vs. Python 3

Follow Me

Please follow me to read my latest post on programming and technology if you like my post.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Recent Posts

What is object oriented design patterns

A design pattern is a reusable solution to a commonly occurring problem in software design. They…

7 days ago

Factory Method Design Pattern in OODP

Factory Method is a creational design pattern that deals with the object creation. It separates…

2 weeks ago

Find Intersection of Two Singly Linked Lists

You are given two singly linked lists that intersect at some node. Your task is…

6 months ago

Minimum Cost to Paint Houses with K Colors

A builder plans to construct N houses in a row, where each house can be…

6 months ago

Longest Absolute Path in File System Representation

Find the length of the longest absolute path to a file within the abstracted file…

7 months ago

Efficient Order Log Storage

You manage an e-commerce website and need to keep track of the last N order…

7 months ago