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

Select a Random Element from a Stream

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

1 day ago

Estimate π Using Monte Carlo Method

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

3 weeks ago

Longest Substring with K Distinct Characters

Given an integer k and a string s, write a function to determine the length…

3 weeks ago

Staircase Climbing Ways

There is a staircase with N steps, and you can ascend either 1 step or…

4 weeks ago

Autocomplete System Implementation

Build an autocomplete system that, given a query string s and a set of possible…

4 weeks ago

Job Scheduler Implementation

Design a job scheduler that accepts a function f and an integer n. The scheduler…

4 weeks ago