NPTEL Python Notes
NPTEL Python Notes
BASICS OF PYTHON Ans. Data science is a multidisciplinary blend of data inference, algorithm development,
and technology in order to solve analytically complex problems. Big data analytics is the
1. Can we convert ‘int’ into ‘string’ datatype? use of advanced analytic techniques against very large, diverse data sets that include
Ans: Yes, we can convert an ‘int’ into a ‘string’ datatype, but the vice versa is not always structured, semi-structured and unstructured data, from different sources, and in different
possible. sizes from terabytes to zettabytes.
Example:
7. Where to execute the command cd to change the working directory? Is it in
command prompt or somewhere else? If it is command prompt how it gets affected
by the Spyder tool?
Ans. You can use the spyder interface itself to set your directory using cd command. No
need to use the command prompt.
2. What is anaconda distribution? 10. What is an IDE and why should we use IDE?
Ans. Anaconda is a free and open-source distribution of the Python and R programming Ans. An IDE stands for Integrated Development Environment. I t is a software application
languages for scientific computing (data science, machine learning applications, consisting of a cohesive unit of tools required for development. It is designed to simplify
large-scale data processing, predictive analytics, etc.), that aims to simplify package software development. Utilities provided by IDEs include tools for managing, compiling,
management and deployment. deploying and debugging software.
3. Why do we use Spyder? Can we use Pycharm? 11. Can I use a jupyter notebook?
Ans. You can use PyCharm as well. From a teaching point of view Spyder provides a Ans. If you are new to programming, better to use Spyder, if you are experienced, you
very good interface. can use jupyter.
4. What is the maximum number of variables that we can delete using "del a,b,c.....n"? 12. When is the assignment operator ‘==’ used?
Is it many or is there any limit to [Link] variables? Ans. The ‘==’ operator is used to check if the values of the two variables are equal or not,
Ans. There is no limit for deleting the variables. You can delete ‘n’ number of variables if it is equal it will return true or else it will return false.
using del command.
13. There are various editors available like notepad++ , visual studio etc . Why and
5. What is the full form of SAS and SPSS ? where do you use it?
Ans. SAS-Statistical Analysis System & SPSS-Statistical Package for the Social Sciences Ans. Editors are used to run the python program as per your application..
Like spyder is used when you want to observe dataset in data science..
Jupyter is useful when you want to run the python program with its running notes,
storing images links with it etc... 22. How important is precedence in an operator?
Ans. If more than one operator is involved in an expression, Python language has a
14. How can I Clear Console? predefined rule of priority for the operators. This rule of priority of operators is called
I am trying to clear the console (Output). I am trying to use %Clear. But it shows an operator precedence.
error.
Ans. It's %clear(small c). Or else place the cursor in the console window and you can use 23. What is the difference between anaconda software and the syder software?
the shortcut key Ctrl+L from the keyboard. Ans. Anaconda is a tool box. It provides different IDEs. Spyder is one of the many IDEs
that Anaconda provides.
15. What is version control?
Ans. Version control is a system that records changes to a file or set of files over time so 24. What about specifying data type for a variable that is not assigned a value. Should it
that you can recall specific versions later. be specified before hand or will python figure it out as the program progresses.
Ans. Python automatically figures out the datatype of each variable with value assigned
16. Can we either work on pycharm ? to it.
Ans. Pycharm is the advanced version of python. You can use Pycharm if you are
comfortable with it. 25. What is the relation between data science and python
Ans. Python is a programming language.
17. What is the difference between pascal and camel case? Data science is a multidisciplinary blend of data inference, algorithm development, and
Ans. Pascal- capitalizes each word ex: PascalCase technology in order to solve analytically complex problems.
Camel Lower Casing - is similar to pascal case but the first word is not capitalized
Camel Upper Casing - is similar to pascal case but the first word is capitalized 26. How to set the working directory?
There are three ways to set a working directory
18. an we save the file in any format ?
C ● Icon
Ans. You have to save a file in .py format in order to use it later. ● Using library os
● Using command cd
19. How to open multiple files in python spyder? Using Icon:
Ans. Although clicking on the Spyder icon will not allow you to open two instances, you
can open a second instance by simply going to the folder where [Link] is and running
[Link] from the command line.
20. I have an excel sheet that has string values and I need to convert to float. But I'm
getting an error Valueerror: could convert string to float. what to do in such cases?
Ans. Not all string values can be converted to float. String values like '2' can be converted
to float since these are numerical values enclosed between quotes. However if you have a
string value 'ABC' you will not be able to convert them to float.
false
+, -, , /, //, * and % are known as operators and these operators can be unary or binary
A unary operator has only one operand
The unary - (minus) operator yields the negation of its numeric argument ‘is not’ operator - evaluates to false if the variables on either side of the operator
The unary + (plus) operator yields its numeric argument unchanged point to the same object and true otherwise
The unary ~ (invert) operator yields the bit-wise inversion of its plain or long integer argument
In [4]:
b = 15.6
Example if (type(b) is not float):
print ("true")
else:
print ("false") # returns false because the data type of 'b' is 'float' not 'int'
The - (minus) operator is used to negate any positive number
false
In [1]:
-15 Membership operators are operators used to validate the membership of a value in a sequence
The membership operators are 'in' and 'not in'
In [2]:
Identity operators are used to compare if two objects are same with the same memory location x = [1,2,3,4,5]
They are usually used to determine the data type of a variable
print(4 in x) # returns True because 4 exists in the x
The identity operators are 'is' and 'is not'
True
‘is’ operator - evaluates to true if the variables on either side of the operator
point to the same object and false otherwise ‘not in’ operator - evaluates to true if it does not find a variable in the specified
sequence and false otherwise
In [6]:
y = [1,2,3,4,5]
True
localhost:8888/notebooks/Desktop/[Link] 3/3
WEEK-2 FAQs
General- FAQs
1. In a list the sub level component index starts from 0 and the inner level elements
start from 0 or 1…?
Ans. In python indexing starts from 0 to n-1. For sub level as well it starts from 0
3. When List_1 is concatenated with List_2 , does the length of the List_1 change?
Ans. The length of the List_1 will not change unless you update it in the existing list. If
we assign it to a new variable length of the list changes depending on the number of
elements.
2. To add a new array to an existing array ,I have used the below code
[Link](a,[[10,11,14]],axis=0)
But it added in the end ,why?
Ans. It is due to the append f unction.
append a dds the value at the end of the array.
FREQUENTLY ASKED QUESTIONS 6. What is the difference between data science and big data analytics?
BASICS OF PYTHON Ans. Data science is a multidisciplinary blend of data inference, algorithm development,
and technology in order to solve analytically complex problems. Big data analytics is the
1. Can we convert ‘int’ into ‘string’ datatype? use of advanced analytic techniques against very large, diverse data sets that include
Ans: Yes, we can convert an ‘int’ into a ‘string’ datatype, but the vice versa is not always structured, semi-structured and unstructured data, from different sources, and in different
possible. sizes from terabytes to zettabytes.
Example:
7. Where to execute the command cd to change the working directory? Is it in
command prompt or somewhere else? If it is command prompt how it gets affected
by the Spyder tool?
Ans. You can use the spyder interface itself to set your directory using cd command. No
need to use the command prompt.
2. What is anaconda distribution? 10. What is an IDE and why should we use IDE?
Ans. Anaconda is a free and open-source distribution of the Python and R programming Ans. An IDE stands for Integrated Development Environment. I t is a software application
languages for scientific computing (data science, machine learning applications, consisting of a cohesive unit of tools required for development. It is designed to simplify
large-scale data processing, predictive analytics, etc.), that aims to simplify package software development. Utilities provided by IDEs include tools for managing, compiling,
management and deployment. deploying and debugging software.
3. Why do we use Spyder? Can we use Pycharm? 11. Can I use a jupyter notebook?
Ans. You can use PyCharm as well. From a teaching point of view Spyder provides a Ans. If you are new to programming, better to use Spyder, if you are experienced, you
very good interface. can use jupyter.
4. What is the maximum number of variables that we can delete using "del a,b,c.....n"? 12. When is the assignment operator ‘==’ used?
Is it many or is there any limit to [Link] variables? Ans. The ‘==’ operator is used to check if the values of the two variables are equal or not,
Ans. There is no limit for deleting the variables. You can delete ‘n’ number of variables if it is equal it will return true or else it will return false.
using del command.
13. There are various editors available like notepad++ , visual studio etc . Why and
5. What is the full form of SAS and SPSS ? where do you use it?
Ans. SAS-Statistical Analysis System & SPSS-Statistical Package for the Social Sciences Ans. Editors are used to run the python program as per your application..
Like spyder is used when you want to observe dataset in data science..
Jupyter is useful when you want to run the python program with its running notes,
storing images links with it etc... 22. How important is precedence in an operator?
Ans. If more than one operator is involved in an expression, Python language has a
14. How can I Clear Console? predefined rule of priority for the operators. This rule of priority of operators is called
I am trying to clear the console (Output). I am trying to use %Clear. But it shows an operator precedence.
error.
Ans. It's %clear(small c). Or else place the cursor in the console window and you can use 23. What is the difference between anaconda software and the syder software?
the shortcut key Ctrl+L from the keyboard. Ans. Anaconda is a tool box. It provides different IDEs. Spyder is one of the many IDEs
that Anaconda provides.
15. What is version control?
Ans. Version control is a system that records changes to a file or set of files over time so 24. What about specifying data type for a variable that is not assigned a value. Should it
that you can recall specific versions later. be specified before hand or will python figure it out as the program progresses.
Ans. Python automatically figures out the datatype of each variable with value assigned
16. Can we either work on pycharm ? to it.
Ans. Pycharm is the advanced version of python. You can use Pycharm if you are
comfortable with it. 25. What is the relation between data science and python
Ans. Python is a programming language.
17. What is the difference between pascal and camel case? Data science is a multidisciplinary blend of data inference, algorithm development, and
Ans. Pascal- capitalizes each word ex: PascalCase technology in order to solve analytically complex problems.
Camel Lower Casing - is similar to pascal case but the first word is not capitalized
Camel Upper Casing - is similar to pascal case but the first word is capitalized 26. How to set the working directory?
There are three ways to set a working directory
18. an we save the file in any format ?
C ● Icon
Ans. You have to save a file in .py format in order to use it later. ● Using library os
● Using command cd
19. How to open multiple files in python spyder? Using Icon:
Ans. Although clicking on the Spyder icon will not allow you to open two instances, you
can open a second instance by simply going to the folder where [Link] is and running
[Link] from the command line.
20. I have an excel sheet that has string values and I need to convert to float. But I'm
getting an error Valueerror: could convert string to float. what to do in such cases?
Ans. Not all string values can be converted to float. String values like '2' can be converted
to float since these are numerical values enclosed between quotes. However if you have a
string value 'ABC' you will not be able to convert them to float.