Query related to syntax

While writing hello world quotes have been used inside bracket but while adding two numbers quotes were not used.

1 Like

Hi @shubhamkumar,

In Python, quotes (single or double) are used to denote string literals. When printing a string literal like “Hello World”, you enclose it in quotes. However, when performing addition or any other mathematical operation with numbers, quotes are not necessary.

1 Like

we use quotes to represent strings i.e character or words .But while adding numbers ,the number should not be of string type to make the addition operation. if we use quotes then the variables are concatenated.

strings in python are enclosed in double quotes .even a number when enclosed in quotes becomes a string. Adding strings together is concatination which does not work like normal addition.
output= 35 #concatination
output=8 #addition
also you cannot add a string and a integer , you’ll get an error

Thats because when you write strings you need to specify it to the compiler, which means anything written inside the double quotes (" ") would be printed as it is. But when you want to print some calculations or something which needs to be evaluated then you cant use double quotes. for example if you use print(“1+2”) then your output would be 1+2, but if you run print(1+2) then your output would be 3


In the phrase Hello world quotes have been used so that the the compiler identifies it as a string. Not putting it in quotes could have generated an error.
However, quotes are not used while adding numbers because it is an integer type.
For instance, if we were to write
we would get an output like: 1020, because they are interpreted as strings and are concatenated.
whereas, if we write print(10+20)
the output is 30, as they were interpreted as integers.

Certainly! Python syntax refers to the rules and conventions that dictate how Python code should be written in order to be valid and interpretable by the Python interpreter. Proper adherence to Python syntax is crucial for the code to execute without errors and produce the desired results.

Here are some key points about Python syntax:

  1. Statements and Indentation:

    • Python uses indentation to define blocks of code instead of curly braces like many other programming languages. Indentation is essential for defining the scope of loops, functions, and conditional statements. The standard convention is to use four spaces for each level of indentation.
  2. Variables and Data Types:

    • In Python, you don’t need to declare variables explicitly before using them. You can directly assign values to variables, and Python will dynamically determine their data types.
    • Common data types include integers, floats, strings, lists, tuples, dictionaries, sets, and more.

    • Comments are used to add explanatory notes within the code. In Python, comments start with the hash (#) symbol, and they are ignored by the interpreter during execution.
  4. Conditional Statements:

    • Python supports if, elif, and else statements for conditional execution. The colon (:slight_smile: and indentation are used to indicate the code blocks.
  5. Loops:

    • Python provides for and while loops for iteration. The for loop iterates over elements in a sequence, while the while loop executes as long as a given condition is true.
  6. Functions:

    • Functions in Python are defined using the def keyword, followed by the function name, parameters, and a colon. The function’s body is indented.
  7. Importing Modules:

    • To use external functionality in Python, you can import modules using the import statement.

Here’s a simple example that demonstrates some of these Python syntax elements:

# Comment
name = "John"  # Variable assignment
age = 30

if age > 18:  # Conditional statement
    print(f"{name} is an adult.")
    print(f"{name} is a minor.")

for i in range(5):  # For loop

def add_numbers(a, b):  # Function definition
    return a + b

result = add_numbers(3, 5)  # Function call
print("The sum is:", result)

Remember to pay attention to proper indentation and the correct use of syntax elements to ensure your Python code runs smoothly. If you have any specific questions or need more information about a particular Python syntax element, feel free to ask!

Within quotes the matter or data type is called string.
example :
print(“hello world”)
it will print hello world.

when two number used in quotes it read it as string.
it will print “2+5”
if when we add two numbers without quotes
it will print 7.

quotes are used for string, which is not needed for integers

Hi @shubhamkumar
When printing “Hello, World!” to the console or output in many programming languages, you often use a function or statement that takes a string as an argument. In many cases, you enclose the string within quotation marks to indicate that it is a sequence of characters.

When performing mathematical operations like addition, you typically work with numeric values directly, without enclosing them in quotes. This is because you want to perform a mathematical calculation, not treat the values as text.

The reason for these differences is that programming languages are designed to handle various types of data and operations, and the syntax is tailored to the specific needs of each task. In some cases, you’ll work with strings that need quotes, while in others, you’ll work with numbers that don’t need quotes.

I think this will help you

Hi. This is because when a string literal i.e. words that includes alphabets only we would have to use double quotes in order to print it whereas while typing numerals it is not needed.

In Python, when you’re writing a simple string like “Hello, World!” inside parentheses or brackets (e.g., print("Hello, World!")), you enclose the string in double quotes (") or single quotes (') to indicate that it’s a string literal. This is because Python uses quotes to delimit string literals, and it’s a way of explicitly telling Python that you’re working with a string.

On the other hand, when you’re adding two numbers together, you don’t need to enclose them in quotes because you’re not working with string literals; you’re working with numeric values. Python recognizes numeric literals without the need for quotation marks.

It is simply the syntax of python and most other programming languages
We need to write strings enclosed in single or double quotes
this is our way to differentiate ‘5’ from the number 5 in python.

imagine if we want to write “THE WINNER IS CANDIDATE NUMBER 5”
Although we are writing the number 5 but in order to print this statement we simply do


In python,
To print a string we enclose the “String” in double quotes,

print(“Hello World”)
Hello World ← Like this
and Numbers are printed as
This is because the number 5 is treated as a number, on which we can perform different arithmetic operations such as :
12 ← gets printed
10 ← output

Whereas if we try to perform arithmetic operations while enclosing these numbers inside double quotes(" ") only ‘+’ will work as concatenation (joining the two strings), other functions such as multiplication and division won’t work.

print(“3” * “5”)

print(“5” + “2”)
52 ← output