Python Programming in Hindi

I am getting an error when importing pytorch.I have already installed pytorch using anaconda.Here is the error:modulenotfounderror: no module named ‘torch’

import torch

ModuleNotFoundError: No module named ‘torch’

I am getting an error after all the elements are printed when i run my python script:”list index out of range in python”:here is the code

list1 = [‘Apple’, ‘Banana’, ‘Orange’]
while i <= len(list1):
i += 1

IndentationError: expected an indented block is what the console returns when my code is exactly what is on a video lesson

name = input("What’s your name? ")

if name == “Kris”:

print(name + " is a lumberjack and he is ok!")


print(name + " sleeps all night and " + name + “works all day!”)

The string index out of range comes when the index you are trying to access does not exist.

The value of i which you are using to access the list is going beyond the number of elements in the list which is causing the list index out of range error.You can correct the code by changing the condition of while loop like this:

list1 = [‘Apple’, ‘Banana’, ‘Orange’]
while i < len(list1):
i += 1

You should properly install pytorch using anaconda.The proper way to install pytorch to anaconda is following

conda install -c pytorch pytorch

First activate your conda profile with “source activate {your_profile}” if not already done and then use the above command.

Python requires formatting of blocks with indentation which basically means that you have to leave spaces before writing a line of code.The code lines belonging to same block must have same exact indentation which means the there must be equal number of spaces before each line of a block.So for you code,the correct formatting is like this:

if name == “Kris”:

print(name + " is a lumberjack and he is ok!")


print(name + " sleeps all night and " + name + “works all day!”)

Putting in an extra space or leaving one out where it is needed will surely generate an error message

The error message IndentationError: expected an indented block would seem to indicate that you have an indentation error which is also sometimes caused by a mix of tabs and spaces. The indentation can be any consistent white space . It is recommended to use 4 spaces for indentation in Python, tabulation or a different number of spaces may work, but it is also known to cause trouble at times. Tabs are a bad idea because they may create different amount if spacing in different editors .

%s is used to format the string syntax and it was taken from C.

I am trying to execute following code :

Given a getStr() function, write the necessary sequence of operations to transform the string (containing three literals) in such a way that every literal is tripled? respectively.

def getstr(s) :
result = 0
for i in s :
result = result + int(s[i] * 3)
#strlen = len(s)
return result


And it gives me a following error

How to convert string to JSON using Python?

How to display column names of Pandas Dataframe?

What is inplace in python and how does it affect my data it?Here is my code where I am using it.

df.dropna( inplace=True)

I have been getting this error: Unexpected indent in python? I have used indentation but till I am getting this error.

How to change directory in python?

What is the difference between sort() and sorted() methods in python?

You can use os module to do so,here is an example to change directory to a certain path.


The path should be passed as a string,more preferably a raw string.

When you set inplace as True,the data in your case df is changed, we can say that it permanently changed your dataframe df.
On the other hand when you use inplace=False,the change does not occur in the original data df.Instead it performs the operation and returns a copy of the object, so you’d use:


Now your original data is unchanged.Sometimes you want the copy of your original dataframe and it can be useful then.

Here is how we can convert string to JSON using Python

import json

s = ‘{“success”: “true”, “status”: 200, “message”: “Hello”}’

d = json.loads(s)

print (d[“success”], d[“status”])

For a dataframe df, the below code to display the column names:


The sort() method modifies the list it is called on whereas, sorted() method creates a new list containing a sorted version of the list it is given and will not modify the list passed as a parameter.
If you want to sort a list but still have the original unsorted version, then you would use the sorted() method. If maintaining the original order of the list is unimportant, then you can call the sort() method on the list.