0

what is the meaning of "" double quotation mark in python like in helpers.py of sentiments link to sentiments

I have one more doubt that is how to deal with the array of integers in python

Answer with example is code is more helpful

Thank you helping!

1

enclosing a set of characters inside a double quotes tells the interpreter to treat it as a string so you can perform the respective operations with it. e.g. "Hello", "123", "5", "5df", etc.

In python array is referred to as a List and it is more flexible that C array as you can add and delete elements dynamically with no pre-definition of the size of list.

Creating empty list in python: myList = [] , notice the use of square brackets.

Similarly a preloaded list: myList = [1, 2, 3 , "four"], in Python list, a list can contain multiple data types.

So delete and insert elements you may use python list methods like list.append() and list.pop() which by default inserts and deletes from the end of list.

For more depth you can visit the official python tutorial page: https://docs.python.org/3/tutorial/

| improve this answer | |
1

Both single and double quotation marks in python are used to specify some string data. For instance

def func():
    """This is a docstring, it's similar to what a comment is!""""
    a = 'This is a string'
    b = "I am Knuth's fan."
    print(a)
    print(b)

# Calling the function
func()
# Everything in python is Object, even functions!
print(func)
# Accessing a docstring
print(func.__doc__)

The output shall be

This is a string
I am Knuth's fan.
<function func at 0x7fbc5853cf28>
This is a docstring, it's similar to what a comment is!

As you can see, both a and b are examples of strings. By using single quotation marks, you can avoid using the slashes for the double quotes and vice versa.

Everything in python is an object, and so do functions. The third output statement may vary on your computer.

Lastly, 3 double quotations marks are also used in python. These are called Docstrings. These work similar to as comments, but are not used the same way. They are used to give a brief summary of what a module/class/function is going to do, just in the starting of them, and not in the middle of the body. Since docstrings are special, they can be accessed using doc attribute of the object it is associated with.


Coming to your next doubt regarding how to deal with array of integers in python, firstly, array is not a buil-in datatype in Python. We have something called list, which is simply a collection of objects. You may be interested in the array module, which is built-in in the Standard Library.

>>> a = ["Jack", 5, func, [7,8], 10.0]
>>> a
['Jack', 5, <function func at 0x7fbc5853cf28>, [7, 8], 10.0]
>>> from array import array
>>> arr = array('i', [1,5,9,7,8,4,6,3])
>>> arr
array('i', [1, 5, 9, 7, 8, 4, 6, 3])
>>> arr[1]
5
>>> arr[2]
9
>>> arr.append(54)
>>> arr
array('i', [1, 5, 9, 7, 8, 4, 6, 3, 54])
>>> arr.pop()
54
>>> arr.pop()
3
>>> arr.insert(3, 60)
>>> arr.insert(3, 60)
>>> arr
array('i', [1, 5, 9, 60, 60, 7, 8, 4, 6])
>>> arr.count(60)
2
>>> arr.tolist()
[1, 5, 9, 60, 60, 7, 8, 4, 6]
>>> arr.tostring()
b'\x01\x00\x00\x00\x05\x00\x00\x00\t\x00\x00\x00<\x00\x00\x00<\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x04\x00\x00\x00\x06\x00\x00\x00'
>>> arr.reverse()
>>> arr
array('i', [6, 4, 8, 7, 60, 60, 9, 5, 1])
>>> arr.remove(60)
>>> arr
array('i', [6, 4, 8, 7, 60, 9, 5, 1])

I hope you got your doubt resolved. You can play with the array module, refer to the documentation.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .