Python Basic Syntax

« Previous Tutorial Next Tutorial »

Here, you will learn about basic syntax of a python program. Basic syntax of a python program is too simple than other languages. Let's take an example, here the following program prints "Hello Python, I am Python Basic Syntax" as output:

# Python Basic Syntax - Example Program
print("Hello Python, I am Python Basic Syntax");

Here is the sample output of the above Python program:

python basic syntax

As you can see from the above Python program, there is only one statement required to print the string "Hello Python, I am Python Basic Syntax".

Read User Input from Keyboard in Python

You can use input() function to read input from the keyboard in python. Here is an example program, demonstrating, how to get and read input from user in python:

# Python Basic Syntax - Example Program

strn = input("Enter your name: ")

print("You name is ", strn);

Here is the sample run of the above python program:

python read user input

Identifiers in Python

Identifiers in Python, is simply a name given to identify the variable, function module, class, or any other object in the Python program. In Python, you can name an identifier with a letter (a-z or A-Z) or underscore (_) character, followed by more letters, digits (0-9) or underscore.

Note - Python is case sensitive language, therefore Codescracker and codescracker are the two different identifiers in Python.


Here is an example illustrates identifiers in python. This program also shows you that python is a case sensitive language:

while True:
	print("Enter 'x' for exit.")
	codescracker = input("Enter your name: ")
	Codescracker = input("Enter your friend's name: ")
	if codescracker == 'x':
		print(Codescracker,"is your friend.\n")

Here is the sample run of the above python program:

python basic syntax example

Comments in Python

Comments are ignore by the Python interpreter, therefore comments helps us in debugging the program. Comments in python, also helps in reviewing the python code later. All characters after hash (#) sign referred as comment, up to the physical line end. Here is an example of comment in Python:

# Python Basic Syntax - Example Program
# We are comments
print("Hello World, I am Python"); # i am also comment

This will produce the following output:

python comments

More Examples

Here are list of some more examples, you may like:

« Previous Tutorial Next Tutorial »


Quick Links
Signup - Login - Give Online Test