Ask Programiz - Human Support for Coding Beginners

Explore questions from fellow beginners answered by our human experts. Have some doubts about coding fundamentals? Enroll in our course and get personalized help right within your lessons.

  • All
  • Python
  • C
  • Java
  • CPP
  • SQL
  • JS
  • HTML
  • CSS
Anuj Shrestha
Expert
2 weeks ago
Anuj Shrestha answered

In Python, semicolons are optional and are generally not used. You can add one at the end of a line, but it isn’t required.

Feel free to try the code below in the editor on the right (or switch to the Code tab if you’re on mobile):

print("Hello, World!");

You'll see this code works just fine.

And I see you’ve started your Python journey. Nice... If you have more questions along the way, just let me know.

Python
This question was asked as part of the Learn Python Basics course.
Anuj Shrestha
Expert
2 weeks ago
Anuj Shrestha answered

Hi! Good observation but the summary is actually correct, and the confusion usually comes from how the word immutable is used.

In Python, a set itself is mutable. This means you can add or remove items from a set after it’s created, which is why the table correctly marks Set → Mutable: Yes.

immutable are the elements inside a set. Every item stored in a set must be immutable (for example: numbers, strings, or tuples). This is why you cannot put lists or other sets inside a set.

So to summarize:

  • Set (container): Mutable ✅

  • Elements inside a set: Must be immutable ✅

If a lesson mentioned that “sets are immutable,” it was likely referring to the elements of a set, not the set itself.

Hope this clears your confusion. Feel free to ask again. I will take a look at the previous lesson too to make sure we are clarifying it properly. Thanks for asking.

Python
This question was asked as part of the Learn Python Basics course.
Ambika Pravin Sonawane
PRO
2 weeks ago
Ambikacountry asked
N
Expert
2 weeks ago
Nisha Sharma answered

Hello! enumerate() is just a simple Python helper that lets you loop through a list and get two things at once:

  1. the index (position) of an element

  2. the value (the actual item) of the element

Example:

fruits = ["apple", "banana", "cherry"]

for index, fruit in enumerate(fruits):
    print(index, fruit)

Output:

0 apple
1 banana
2 cherry

So instead of manually keeping a counter yourself, Python does it for you.

And I see that you've asked this question based on the code below:

def two_sum(num_list, target_value):
    
    dictionary = {}

    for index, value in enumerate(num_list): 
        # add items of num_list to dictionary
        # value as key and index as value
        dictionary[value] = index
    
    for i in range(len(num_list)):
        complement = target_value - num_list[i]
        
        # check if item's complement is present in dictionary
        if complement in dictionary and dictionary[complement] != i:
            
            # return element index and complement's index
            return [i, dictionary[complement]]
    
num_list = [2, 7, 11, 15]
target_value = 9

result = two_sum(num_list, target_value)
print(result)   

In the two_sum() function, enumerate(num_list) is used because you need both the number and where it sits in the list (its index) to store and return the answer.

Hope that helps. Feel free to ping if you need more help or have any more questions.

Python
This question was asked as part of the Complexity Calculation course.
N
Expert
2 weeks ago
Nisha Sharma answered

If you try to write two print() statements on the same line, Python needs a clear separator between them. Without one, Python won’t know where the first print() ends and the next one begins, so you’ll get a syntax error.

For example, this won’t work:

print("Hello") print("World")

But this works perfectly, because the semicolon ; separates the two commands:

print("Hello"); print("World")

You’ll see:

Hello
World

Hope that helps. Feel free to ping if you need more help or have any more questions.

Python
This question was asked as part of the Learn Python Basics course.
N
Expert
2 weeks ago
Nisha Sharma answered

Hello there, good question.

Yep, it still works the same. input() always takes what the user types and gives it back as a string. Adding something like input("Enter temperature in Celsius: ") only shows a message on the screen. It doesn’t change how the value is stored.

So:

  • x = input()x is a string

  • x = input("...")x is still a string

That’s why we usually do float(input()) here, so you can actually do the Celsius-to-Fahrenheit math.

Feel free to reach out if you have any more queries.

Python
This question was asked as part of the Learn Python Basics course.
N
Expert
2 weeks ago
Nisha Sharma answered

Hello there!

Indentation is a common pain point in Python because it’s not just style, it’s part of the syntax. A few rules will save you a lot of errors:

  • For blocks that end with : (like if, for, while, def), the very next line must be indented.

  • Everything inside that block must line up at the same indentation level.

  • Nested blocks go one level deeper (usually 4 spaces).

  • Don’t mix tabs and spaces. Pick one (4 spaces is the standard) and stick to it.

Example:

for i in range(1, n + 1):      # level 0
    if i % 2 == 0:             # level 1
        continue               # level 2 (inside the if)
    print(i)                   # level 1 (outside the if)

If you keep getting errors, it’s usually one line that’s slightly misaligned or tabs are sneaking in. Feel free to reach out if you have any more queries.

Python
This question was asked as part of the Learn Python Basics course.
N
Expert
last month
Nisha Sharma answered

Hello there, good question.

Yes, Python does have some pretty standard naming conventions, and following them makes your code way easier to read (especially when you come back to it later).

  • Use clear, specific names

    • Good: favorite_food, total_price, student_count

    • Not so good: x, temp, data (unless it truly is temporary or generic)

  • Use snake_case for variables

    • Python style is lowercase words separated by underscores (known as snake_case):

    • favorite_food instead of favoriteFood

  • Don’t use Python keywords

    • You can’t name variables things like class, def, if, for, etc.

    • If you really need something close, people often do: class_ (with an underscore at the end)

  • Be consistent with casing

    • Python treats score, Score, and SCORE as different names.

    • Most variables stay lowercase: score, high_score, max_score

  • Special naming patterns you’ll see a lot

    • Constants (values you don’t plan to change): MAX_SPEED, PI, TAX_RATE

    • “Private” / internal use (a hint to other programmers): _hidden_value

    • Avoid names that look like built-ins: don’t name a variable list, str, or sum (you’ll overwrite the built-in function by accident)

If you stick to descriptive names + snake_case, your code will instantly look more professional and be easier to understand.

Feel free to reach out if you have any questions.

Python
This question was asked as part of the Learn Python Basics course.
Udayan Shakya
Expert
last month
Udayan Shakya answered

Hello, Pius! If you want to print \n as part of the string, you'll need to write it as \\n like this:

print ("Hey\\nHow are you")

Just like \n is a special code for entering a new line, \\ is special code for entering a single backslash into the string.

So, Python will interpret \\n as:

Print a single backslash '\' followed by the letter 'n'.

Hope that helps! Contact us again if you have further queries.

Python
This question was asked as part of the Learn Python Basics course.
Abhay Jajodia
Expert
2 weeks ago
Abhay Jajodia answered

Hello Arun! The != symbol is known as the "not equal to" operator in Python. It checks whether two values are not equal to each other. Here's how it works:

  • It returns True when the values are different.

  • It returns False when the values are the same.

For example, in the code you're working with:

number = 21

# This will print False because 21 is equal to 21
print(number != 21)

# This will print False because 50 is equal to 50.0
print(50 != 50.0)

# This will print True because 21 is not equal to 21.1
print(number != 21.1)

In the first two cases, both values are equal, so it prints False. In the last case, 21 is not equal to 21.1, so it prints True.

Keep practicing with these comparison operators, and you'll get the hang of them! If you have more questions, feel free to ask!

Python
This question was asked as part of the Learn Python Basics course.
Udayan Shakya
Expert
last month
Udayan Shakya answered

Hi Ambika! It's natural to get confused by the return statement at the very beginning. So I'll try and help clarify your confusion.

For starters, you can think of a Python function as a machine that takes input (these are the function arguments) and spits out an output (this is the return value).

In other words, the return statement tells the function what "output" to give. You can then use this "function output" (return value) to perform some other operation.

For instance, let's say you need to crate two functions:

  • One for finding the sum of 3 numbers.

  • The other for finding the average from the sum.

Let's see how we can solve this problem.

Bad Practice: Without Using return Statement

# Function to calculate sum of 3 numbers
def calculate_sum(n1, n2, n3):
    total = n1 + n2 + n3
    print(f"Sum = {total}")

# Function to calculate the average of 3 numbers
def calculate_average(n1, n2, n3):
    average = (n1 + n2 + n3) / 3
    print(f"Average = {average}")

calculate_sum(5, 6, 7)
calculate_average(5, 6, 7)

Here, you can't use the sum calculated by the calculate_sum() function inside the calculate_average() function. As a result, we need to calculate the sum all over again inside calculate_average().

There are ways to work around this issue, but they're awkward and unsafe. The most natural and desirable solution is to use the return statement.

Good Practice: Using return Statement

# Function to calculate sum of 3 numbers
def calculate_sum(n1, n2, n3):
    return n1 + n2 + n3

# Function to calculate the average of 3 numbers
def calculate_average(total):
    return total / 3


# Store the return value in my_sum variable
my_sum = calculate_sum(5, 6, 7)

# Print the sum 
print(f"Sum = {my_sum}")

# Pass my_sum as argument to calculate_average()
# And store the return value in my_average
my_average = calculate_average(my_sum)

# Print the average
print(f"Average = {my_average}")

As you can see, using the return statement allows you to use your first calculation in other parts of the program, such as sending it as an argument to the calculate_average() function.

And this is just a small program!

Imagine how handy return values will be when you have to write a large program that has multiple functions, and you need to use the results of those functions in other parts of the program.

This is the true power of the return statement. Hope everything's clear now!

Python
This question was asked as part of the Learn Python Basics course.