Tim Peters en el 2004 descubrió la manera perfecta de poder escribir en Python, y sobretodo nos demuestra que puede escribirse en cualquier idioma y esto te ayuda a hacerlo de una forma clara y fácil de entender y comprender el programa.
Para que se desplieguen estas, tu únicamente debes de escribir “import this” y la magia esta hecha.
Python provides a clean iteration syntax. Note the colon and indentation.
Example
>> for i in range(0, 3):
>> print(i*2)
024
Loops with “while”
A While loop permits code to execute repeatedly until a certain condition is met. This is useful if the number of iterations required to complete a task is unknown prior to flow entering the loop.
Syntax
while condition:
//do something
>> looping_needed = True
>>
>> while looping_needed:
>> # some operation on data
>> if condition:
>> looping_needed = False
I think is time to start with functions, i’m no experts at this topic so maybe we can learn together, let’s go
First, what is a function? Very simple, is a piece of reusable code that can be call upon whenever you need it. In other words, if you are going to repeat a code several time the best you can do is create a function, so you don’t have to write it all over again and again. Is to make your life easier.
To create a function you have to start with def follow by parenthesis (), inside this parenthesis goes the parameters necessary, if needed of course, after the parenthesis goes a colon (:) and then to close it, use the return function follow by the value statement, if you don’t want it to return anything, just leave a blank space, the system will take it like None.
Here is my example:
In this example I can call whenever I want the areacuadro function, that will be all:) #Pug#Tec#TC101#Functions
Here is a webpage where you can find it better explain link
Well…after a long time, I’m going to start publish, and more like that I want to share what I have been learning in the class #TC010 with Ken…lets start!
The comments in Python are notes that you can use when your programs get bigger and more complicated, and this notes help you to know in natural language what the program is doing and the symbol you use are #.
The number type data is used to store numerical values, this are created when you assign a value to the object.
var1 = 5
var2= 15
Pythons support four different numerical types:
int ( signed integers )
long ( long integers, they can also be represented in octal and hexadecimal)
float ( floating point real values)
complex (complex numbers)
Some examples, for a clearer view:
int
long
float
complex
10
51924361L
0.0
3.14j
100
-0x19323L
15.20
45.j
-786
0122L
-21.9
9.322e-36j
080
0xDEFABCECBDAECBFBAEl
32.3+e18
.876j
-0490
535633629843L
-90.
-.6545+0J
-0x260
-052318172735L
-32.54e100
3e+26J
0x69
-4721885298529L
70.2-E12
4.53e-7j
In the other hand we have the String which are a set of values represented inside a quotation mark. Python allows either pairs of single or double. Subsets of the string can be made by a slice operator ([] and [:]). Every set starts at 0 to -1. You can include the sing (+) to add something else and the (*) to repeat that string a number of times. Here is an example for a better understanding:
The next type is the list, where you will find items separated by commas and inside brackets, you can access to this list like the string but the difference is that it will appear the complete list of the place you chose, not only a letter or a value; also like the previous you can add something with the (+) and repeat the list with the (*) and example:
The tuples are very similar to the lists, but the main difference is that the tuples are enclosed between parenthesis and not brackets as the list, and another main point is that
The Pythoneer Tim Peters channeled the benevolent dictator of life guiding principles for Python’s design into 20 aphorisms, only 19 of which have been written down.
1- Beautiful is better than ugly.
2- Explicit is better than implicit.
3- Simple is better than complex.
4- Complex is better than complicated.
5- Flat is better than nested.
6- Sparse is better than dense.
7- Readability counts.
8- Special cases aren't special enough to break the rules.
9- Although practicality beats purity.
10- Errors should never pass silently.
11- Unless explicitly silenced.
12- In the face of ambiguity, refuse the temptation to guess.
13- There should be one-- and preferably only one --obvious way to do it.
14- Although that way may not be obvious at first unless you're Dutch.
15- Now is better than never.
16- Although never is often better than *right* now.
17- If the implementation is hard to explain, it's a bad idea.
18- If the implementation is easy to explain, it may be a good idea.
19- Namespaces are one honking great idea -- let's do more of those!
You can find this information in: https://www.python.org/dev/peps/pep-0020/
#Zen#Pug#TC101#Tec#Python
Continuing with Python, it’s time to learn about the comments, which are no more than pieces of codes that are not supposed to be run by the interpreter. This comments help the programmer understand better the code, and also if for any reason you get confuse, you can find your path once again by reading the comments.
For us to start a comment in Python there is only one requirement, to star with a number sing #.
As you can see, the comments where not run, only the function “print”. There is another use for the comments, let say you have a piece of the code that you don’t want the interpreter to run, but also you don’t want to erase it. What to do? The answer is simple, just turn it into a comment.
For the people that is using eclipse to program, there are certain thing you can do to make your life easier, and your programing, on the top left corner in there is the option “Source” in there you will find two buttons one is Comment and the other one Uncomment, by selecting the piece of code and clicking on of these buttons you will be able to turn that piece of code into a comment or make that comment a piece of code again?.
Here is the video that help me understand comments …