Basics

The Print Statement

There are different ways with which you can print a string along with a variable in Python.


Now, Let's see different options of print statement.


Python's print statement Syntax:

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)


Just print a string:

>>> print("Rhash Algo")

Rhash Algo


Printing multiple values/variables:

>>> print('Rhash Algo', 'is', 'a', 'website', 'for', 'all', 'trending', 'technologies')

Rhash Algo is a website for all trending technologies


Printing multiple values/variables: using sep

>>> print('Rhash Algo', 'is', 'a', 'website', 'for', 'all', 'trending', 'technologies', sep='\n')

Rhash Algo

is

a

website

for

all

trending

technologies


Just print a variable:

>>> name = "Rhash Algo"

>>> print(name)

Rhash Algo

 

Print a string along with the variable using comma:

>>> print("Name of the Organization is:", name)

Name of the Organization is: Rhash Algo


Print a string along with the variable using +: Concatenation

>>> print("Name of the Organization is: " + name)

Name of the Organization is: Rhash Algo


Print a string along with the variable by using %s:

>>> print("Name of the Organization is: %s"%(name))

Name of the Organization is: Rhash Algo


Print a string along with the variable by using format:

>>> print("Name of the Organization is: {}".format(name))

Name of the Organization is: Rhash Algo


Print a string along with the variable by using Formatted String Literals:

>>> print(f"Name of the Organization is: {name}")

Name of the Organization is: Rhash Algo



Comments

First way of specifying the comments in Python:

# This is a comment in Python


city = "New York" # This is also a comment

      # This is another comment


Another way of specifying comments: These are called multi-line comments.

"""

This is a multi-line comment.

In this, we use double or single quotes.

Please use this, whenever you want to have doc string.

"""


Python Data Structures

Python has built-in data structures. They are:


List

>>> [1,2,'4', "Rhash Algo", 4.56]

[1, 2, '4', 'Rhash Algo', 4.56]


Tuple

>>> (1,2,'4', "Rhash Algo", 4.56)

(1, 2, '4', 'Rhash Algo', 4.56)


Dictionary

>>> {"key" : "value", 1 : "one", 'one' : 1, ("set", "can", "be", "a", "key") : "Set can be a key"}

{'key': 'value', 1: 'one', 'one': 1, ('set', 'can', 'be', 'a', 'key'): 'Set can be a key'}


Set

>>> {1,2,'4', "Rhash Algo", 4.56, 1, 2, 2}

{1, 2, 'Rhash Algo', 4.56, '4'}


We will discuss more on these topics in the next sections.