--Originally published at angelmendozas
Author: angelmendozas
Creation and use of ranges in Python
--Originally published at angelmendozas
Range is a variable used in python to select a “range” of values in a list or maybe an input.
Creation and use of dictionaries in Python
--Originally published at angelmendozas
A simple creation of a dictionary
First name your dictionary variable:
f.e. “d1”
Then have clear which parameters will you put in your dictionary and put them inside {}
d1 = {“age”:18, “work”:student, “Name”: Jose Angel}
Use of the conditional “if” and “else”/”elif”
--Originally published at angelmendozas
This is an example from the challenge of the week I made with Carolina Vargas in class.
If is a condition, that states IF some parameters are accomplish then do something and is that IF doesn’t happen the you put ELSE, to do something ELSE… and if that ELSE doesn’t happen then you put another ELSE it’s just that now with ELIF because you can’t repeat the word ELSE.
Creating & Using own modules/libraries.
--Originally published at angelmendozas
To create and use you own modules you better code this:
import potato <- You can call you module whatever you want
potato.example (‘hello’) <-Then in parenthesis the output you want it to have
To install it in mac you use this command in the shell:
pip3 install <package>
and the you run your program on the shell and thats it.
It should print ‘Hello’
Libraries: Importing and using them
--Originally published at angelmendozas
To import a library f.e. math you literally use the command import and followed by the library you want in this case math:
There a lots of Libraries/Dictionaries, you can even create your own ( it’s a lot of work obviously but sometimes necessary).
You can look up on google all the dictionaries that exist.
The results are these:
Functions: Calling and Creating them
--Originally published at angelmendozas
To call a function you use the word “def” followed by the name you want your function to have, after naming your function, you need parameters and these parameters go inside parentheses() and at the end of these you are required to put a “:” then you decide which function to return to get the function you desire and then define your parameters of the functions like this:
And so like this the console should give you 4.
A simple explanation of calling a creating a function is using the commands told before and then naming however you want your function to be called and which one you want in return, and finally give values to your functions.
Obviously there are more complex ways to use functions, but for now I will just explain the basic.
Spanish ISC Poem
--Originally published at angelmendozas
Y AHORA, UN POEMA…
MI PADRE QUERIA UN ARQUITECTO
MI MADRE QUERIA UN DOCTOR
AL FIN, NINGUNO SE DECIDIO
ENTONCES SALI PROGRAMADOR!
Basic Input in Python
--Originally published at angelmendozas
You use raw_input so the user can put an input and the question or thing you want him to fill
In the shell the question is dropped and you write your name
Just After you write your name, the shell prints what you told it to print, for example I programmed print(‘Your name is ‘ + x), because the result of x is your name and it prints this:
Basic PYTHON output (print)
--Originally published at angelmendozas
“print” is the basic output for python and you can use it like this:
print = ‘Hello World’
and the output should be:
Hello World
So there actually no rocket science behind this, you put between commas whatever you want and it’ll print that.