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

Find Intersection of Two Singly Linked Lists

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

18 hours ago

Minimum Cost to Paint Houses with K Colors

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

3 days ago

Longest Absolute Path in File System Representation

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

3 weeks ago

Efficient Order Log Storage

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

1 month ago

Select a Random Element from a Stream

You are given a stream of elements that is too large to fit into memory.…

1 month ago

Estimate π Using Monte Carlo Method

The formula for the area of a circle is given by πr². Use the Monte…

2 months ago