<center></center> <br/> [Maybe I dived too deeply into advanced stuff the last part](https://steemit.com/programming/@profitgenerator/learn-basic-python-programming-ep-5-let-s-build-a-password-strength-analyzer), but I just wanted to show you how powerful Python is and you can code basically anything with it. Some tools can be extremely useful especially for crypytocurrency holders. You can even build a trading bot for Poloniex and Bittrex in Python, using their API system, it would be a piece of cake. It would be harder to just just make it profitable, but the code itself can be easily made. Ok but let's go back to novice level and let me teach you more basic things like arrays and file operations. An [array](https://en.wikipedia.org/wiki/Array_programming) is like a variable that has multiple elements but each of them can be indexed. In Python even a string which is supposed to be an unitary variable can be indexed, but an array is specifically for indexing. * An integer variable is like this: 12345 * An array variable is like this [1,2,3,4,5] (where each element has an index, the number 5 will have an index of 4 because the count starts always from 0) An array can be initialized, which means that it's size is specified: `array_A = [0] *5` This will create an array of size 5, where each element is filled with 0. Of course the array can later be extended if needed. Or you can create an empty array and fill it up later: `array_B = []` To fill up an array we can use the `for` loop which we learned about in [EP 3](https://steemit.com/programming/@profitgenerator/learn-basic-python-programming-ep-3-logic-and-loops): ```python for x in range(5): array_B.append(x) ``` <BR/> This will create an array of size 5, and it will fill it up from 0 to 4.  <BR/>  <BR/> ---------------------- <BR/> # File Operations Working with file is also easy. There are 2 basic things, reading from a file and writing to a file. For simplicity we will use a plaintext .txt basic file. It will be a simple file just containing 3 hellos in 3 separate lines, like this:  The name of the file is simply `hello` or you can name it `hello.txt` if that is better: Now let's read the contents of this file and print it out: ```python f = open("hello","r") content = f.read() f.close() print (content) ``` <BR/> `f` is the file variable object, we open it, in the first argument we specify the name `hello` or `hello.txt`, then the method which is: * `r` for reading * `w` for writing * `b` for binary operations Then the content variable will contain all data, as the `read()` function reads the entire file into memory. This is simple and easy but it might be problematic for big files (100 MB larger) where streamreading is recommended instead of reading everything in the memory. It's also very important to close the file after finishing using it, otherwise the file can be corrupted by disk flushing and things like that. So this comment just return the content of the file:  But in this instance, the content variable is just a long string, the entire file is read in like a long string of text. You might want to read it in line-by-line instead and store each line in a separate array element, for that do it like this: ```python with open("hello","r") as f: content = f.readlines() f.close() print (content[0]) ``` <BR/> This code will just read in the file line by line, until the end of the file, and here the `content` variable is a string array not just a simple string. So by printing out `content[0]` we print out only the first line:  If you want to print out the entire file this way you need to iterate through all of it like this: ```python with open("hello","r") as f: content = f.readlines() f.close() for x in range(len(content)): print (str(x)+" Line Content:" + content[x]) ``` <BR/> Where we specify the length of the array in the range with the `len()` function, remember it's 3 since we have 3 lines. And then print out them line by line and also add some text before it. We show the `x` variable which will count the index of it, which is always -1 of the size of it, since it starts from 0. So the size of the array is 3, but the index of the last element is 2.  ------------------------------------------------- That's it, I hope you learned something new, I am telling you these are just the basics, there are many more interesting things you can do with these tools. <BR/> --------------------------- ***Disclaimer: Code licensed under [MIT license](www.opensource.org/licenses/MIT), use this code at your own risk, I will not be responsible for any losses.*** ------------------------------------------ **Sources:** https://pixabay.com Python is a trademark of the [Python Software Foundation](https://www.python.org/psf/) ------------------------------------------- <CENTER><H1>Upvote, ReSteem & <a href="https://steemit.com/@profitgenerator" target='_blank'><img src='https://s4.postimg.org/cfz9b1mnh/bluebutton.png' border='0' alt='bluebutton'/></a></H1> </CENTER>
author | profitgenerator |
---|---|
permlink | learn-basic-python-programming-ep-6-arrays-and-file-operations |
category | programming |
json_metadata | {"tags":["programming","howto","education","python","tutorial"],"image":["https://steemitimages.com/DQmU3VQGGHcbE5JyZBGTF8iN1d1xustawjxytWr4bP5kMNt/p1.png","https://steemitimages.com/DQmehQ1LtdTd9WNsvS5hPx8zz9pXAP2cQ3JuYW4SM5txrQ3/P1.png","https://steemitimages.com/DQmP4YzKiCi3GBi1drKJrqp5mDkk5M2oLYLvjhH29nHn2vy/P2.png","https://steemitimages.com/DQmbRWpMAkohahCX1DAUMx8VdaEBS27ayFK8PMLyxZPkntR/h1.png","https://steemitimages.com/DQmaAr6sqKkLyDjh61GidxZ5g5gQD3XN4MxiixyTKuaktPz/f2.png","https://steemitimages.com/DQmSAf9U3QRstkT8cs2PiGszwfRk2neJFp7XuUxfDkzLXBb/h2.png","https://steemitimages.com/DQmSNXcaq1vfbZoi4JBUD6xBRJmts2T2nvphzmpX4sEMkv6/H4.png","https://s4.postimg.org/cfz9b1mnh/bluebutton.png"],"links":["https://steemit.com/programming/@profitgenerator/learn-basic-python-programming-ep-5-let-s-build-a-password-strength-analyzer","https://en.wikipedia.org/wiki/Array_programming","https://steemit.com/programming/@profitgenerator/learn-basic-python-programming-ep-3-logic-and-loops","www.opensource.org/licenses/MIT","https://pixabay.com","https://www.python.org/psf/","https://steemit.com/@profitgenerator"],"app":"steemit/0.1","format":"markdown"} |
created | 2017-07-02 21:16:51 |
last_update | 2017-07-02 21:20:00 |
depth | 0 |
children | 8 |
last_payout | 2017-07-09 21:16:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 8.536 HBD |
curator_payout_value | 2.139 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 5,702 |
author_reputation | 68,549,319,463,075 |
root_title | "Learn Basic Python Programming EP.6. - Arrays & File Operations" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 7,065,020 |
net_rshares | 1,469,236,451,080 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
sandra | 0 | 13,901,011,729 | 6% | ||
jason | 0 | 7,740,331,953 | 2.16% | ||
angusleung100 | 0 | 2,230,815,739 | 100% | ||
michaellamden68 | 0 | 3,882,232,317 | 10% | ||
vortac | 0 | 740,316,850,242 | 25% | ||
bola | 0 | 2,461,160,325 | 1% | ||
ace108 | 0 | 84,237,621,724 | 5% | ||
alexpmorris | 0 | 12,792,926,448 | 15% | ||
shaka | 0 | 464,755,698,553 | 13% | ||
dumar022 | 0 | 26,909,799,528 | 14% | ||
matthewtiii | 0 | 14,166,695,568 | 100% | ||
profitgenerator | 0 | 20,514,827,853 | 100% | ||
saamychristen | 0 | 13,792,637,744 | 50% | ||
freebornangel | 0 | 2,229,776,601 | 4% | ||
smasher | 0 | 682,806,696 | 13% | ||
lilypanama | 0 | 2,093,469,849 | 100% | ||
sellergenius | 0 | 785,728,232 | 25% | ||
steemcollator | 0 | 3,546,145,962 | 10% | ||
fortuneteller | 0 | 1,613,593,127 | 100% | ||
mariaalmeida | 0 | 1,786,076,854 | 50% | ||
carbunco10 | 0 | 366,325,832 | 100% | ||
aismor | 0 | 438,732,952 | 100% | ||
velimir | 0 | 207,317,192 | 1.3% | ||
syn999 | 0 | 9,427,844,255 | 100% | ||
rdickey | 0 | 127,503,763 | 100% | ||
dannypc | 0 | 579,544,767 | 100% | ||
kaeptnkook | 0 | 2,382,719,816 | 100% | ||
kskarthik | 0 | 647,314,871 | 100% | ||
enginewitty | 0 | 1,217,361,486 | 100% | ||
live2love | 0 | 0 | 100% | ||
sd3913 | 0 | 13,249,552,672 | 100% | ||
sakircevik | 0 | 2,861,177,277 | 100% | ||
bmickov | 0 | 622,885,509 | 100% | ||
gokulnk | 0 | 568,746,652 | 100% | ||
whd | 0 | 2,560,027,589 | 100% | ||
c-o-l-e | 0 | 0 | 100% | ||
btcunchained | 0 | 7,114,370,597 | 100% | ||
wintermute | 0 | 644,185,795 | 100% | ||
welcomesteemians | 0 | 359,814,678 | 100% | ||
arabarea | 0 | 800,877,646 | 100% | ||
rmb | 0 | 1,096,851,768 | 100% | ||
pro20 | 0 | 238,340,876 | 100% | ||
qed | 0 | 1,143,278,339 | 100% | ||
eddyova | 0 | 934,354,246 | 100% | ||
alexandruionescu | 0 | 388,830,552 | 100% | ||
luis1992 | 0 | 818,284,906 | 100% |
Thanks @profitgenerator !!!
author | alexandruionescu |
---|---|
permlink | re-profitgenerator-learn-basic-python-programming-ep-6-arrays-and-file-operations-20170702t212026884z |
category | programming |
json_metadata | {"tags":["programming"],"users":["profitgenerator"],"app":"steemit/0.1"} |
created | 2017-07-02 21:20:27 |
last_update | 2017-07-02 21:20:27 |
depth | 1 |
children | 1 |
last_payout | 2017-07-09 21:20:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 27 |
author_reputation | 4,243,893,540,414 |
root_title | "Learn Basic Python Programming EP.6. - Arrays & File Operations" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 7,065,359 |
net_rshares | 591,950,989 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
alexandruionescu | 0 | 591,950,989 | 100% |
No problem my pleasure teaching people about python.
author | profitgenerator |
---|---|
permlink | re-alexandruionescu-re-profitgenerator-learn-basic-python-programming-ep-6-arrays-and-file-operations-20170702t212436200z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-07-02 21:24:45 |
last_update | 2017-07-02 21:24:45 |
depth | 2 |
children | 0 |
last_payout | 2017-07-09 21:24:45 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 52 |
author_reputation | 68,549,319,463,075 |
root_title | "Learn Basic Python Programming EP.6. - Arrays & File Operations" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 7,065,770 |
net_rshares | 0 |
I have been learning python until i stoped.I love python and I will love to continue.Is there any e-book you can recommend for easy understanding?Thanks.
author | g-power |
---|---|
permlink | re-profitgenerator-learn-basic-python-programming-ep-6-arrays-and-file-operations-20170703t044941943z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-07-03 04:49:57 |
last_update | 2017-07-03 04:49:57 |
depth | 1 |
children | 1 |
last_payout | 2017-07-10 04:49:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 153 |
author_reputation | 387,285,167,103 |
root_title | "Learn Basic Python Programming EP.6. - Arrays & File Operations" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 7,099,871 |
net_rshares | 0 |
I dont know just watch some youtube videos I am sure there are many tutorials out there in a playlist, just learn from there, easier.
author | profitgenerator |
---|---|
permlink | re-g-power-re-profitgenerator-learn-basic-python-programming-ep-6-arrays-and-file-operations-20170703t120000900z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-07-03 12:00:21 |
last_update | 2017-07-03 12:00:21 |
depth | 2 |
children | 0 |
last_payout | 2017-07-10 12:00:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 133 |
author_reputation | 68,549,319,463,075 |
root_title | "Learn Basic Python Programming EP.6. - Arrays & File Operations" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 7,133,249 |
net_rshares | 0 |
I will always think that learning python programming is a bad choice. It offers a lot of syntactic sugar so you do not learn how to solve programming problems
author | whd |
---|---|
permlink | re-profitgenerator-learn-basic-python-programming-ep-6-arrays-and-file-operations-20170702t213550161z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-07-02 21:35:48 |
last_update | 2017-07-02 21:35:48 |
depth | 1 |
children | 3 |
last_payout | 2017-07-09 21:35:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 158 |
author_reputation | 17,817,550,622,492 |
root_title | "Learn Basic Python Programming EP.6. - Arrays & File Operations" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 7,066,829 |
net_rshares | 0 |
But you can interact easily with a Linux machine and that is what matters. People should not use Windows anyway due to security and privacy concerns, so if they arleady use Linux they might was well just learn Python programming.
author | profitgenerator |
---|---|
permlink | re-whd-re-profitgenerator-learn-basic-python-programming-ep-6-arrays-and-file-operations-20170702t213723200z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-07-02 21:37:39 |
last_update | 2017-07-02 21:38:12 |
depth | 2 |
children | 2 |
last_payout | 2017-07-09 21:37:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 229 |
author_reputation | 68,549,319,463,075 |
root_title | "Learn Basic Python Programming EP.6. - Arrays & File Operations" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 7,066,990 |
net_rshares | 0 |
Is is hard to use C on Linux machine? I want to show you example of "syntactic sugar" i mentioned for example plaindrome problem can be solved with python in such manner ``str(n) == str(n)[::-1]`` Anyway good tutorial voted up:)
author | whd |
---|---|
permlink | re-profitgenerator-re-whd-re-profitgenerator-learn-basic-python-programming-ep-6-arrays-and-file-operations-20170702t215037786z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-07-02 21:50:36 |
last_update | 2017-07-02 21:50:36 |
depth | 3 |
children | 1 |
last_payout | 2017-07-09 21:50:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 228 |
author_reputation | 17,817,550,622,492 |
root_title | "Learn Basic Python Programming EP.6. - Arrays & File Operations" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 7,067,942 |
net_rshares | 0 |