Python Basic Syntax

Print statement

The print() function is used to display text on the console.


print("Hello, World!")


Comments in Python start with the ‘#’ symbol and are used to add notes and explanations to your code. They are ignored by the Python interpreter and do not affect the execution of your program.


# This is a comment in Python
print("Hello World!") # This is another comment


In Python, you can create variables to store data. Variables are declared by assigning a value to a name, and their data type is inferred automatically based on the value assigned. Variable names can contain letters, numbers, and underscores, but cannot start with a number.


# Creating variables in Python
x = 5 # integer
y = "Hello" # string
z = True # boolean

Data Types

Python has several built-in data types, including integers, floats, booleans, strings, lists, tuples, and dictionaries. These data types can be used to store and manipulate different types of data.


# Data types in Python
x = 5 # integer
y = 3.14 # float
z = True # boolean
name = "John" # string
fruits = ["apple", "banana", "orange"] # list
t = (1, 2, 3) # tuple
person = {"name": "John", "age": 30} # dictionary

Conditional Statements

Conditional statements are used to execute different blocks of code based on a certain condition.


x = 10
if x > 5:
    print("x is greater than 5")
    print("x is less than or equal to 5")


Loops are used to execute a block of code repeatedly.


for i in range(5):


Functions are reusable blocks of code that perform a specific task.


def greet(name):
    print("Hello, " + name + "!")


Python Docstrings

Python also has multi-line commenting capability. Docstrings can be one line, or multi-line.
Python uses Tripple quotes at the beginning and end of the docstrings.

"""This is a 
multiline docstring."""
print("Hello, World!") 

These are just a few examples of the basic syntax in Python. Python has a wide variety of built-in functions and modules, as well as an extensive library of third-party packages, making it a versatile and powerful language.

Wordpress Social Share Plugin powered by Ultimatelysocial
Wordpress Social Share Plugin powered by Ultimatelysocial