Im new to the python programming and I wanted to know how to write an array using python
how to write an array using python
Collapse
X
-
Yea, just wanted to add that python has other array-like data types too:Originally posted by Motoma[code=python]
arr = [1, 2, 3, 'four', [5, 6]]
[/code]
Tuples are like lists except they can't be modified (immutable):
[code=python]
myTup = (1, 2, 3, "string", (5, 6), ["string2", 9])
[/code]
Dictionaries are like the C++ maps, they store corresponding values:
[code=python]
myDict = {"val":6, "val2":8, "val3":10}
[/code]Comment
-
You can use enumerate():Originally posted by nubean19Thanks, one more thing how do you uss a for loop to print out lines with the line number, followed by the word
[code=python]
lines = ["This is the first line", "This is the second line"]
for (lineNum, line) in enumerate(lines ):
print lineNum + 1, line # enumerate returns the index which starts at zero
[/code]
or the index function of lists:
[code=python]
lines = ["This is the first line", "This is the second line"]
for line in lines:
print lines.index(lin e) + 1, line
[/code]Comment
-
I must ask that you please follow the Posting Guidelines for future posts on this site.Originally posted by nubean19Thank you so mush you been a lot of help, im gonna check it and see if it works
Thanks for joining.Comment
Comment