click below
click below
Normal Size Small Size show me how
Python
Programacion python
| Question | Answer |
|---|---|
| Display output | print()_____print("Hi") → Hi--- |
| Get user input | input()_____input("Name")--- |
| Assign value to variable | =_____x=5--- |
| Convert to integer | int()_____int("5") → 5--- |
| Convert to float | float()_____float("2.5") → 2.5--- |
| Convert to string | str()_____str(5) → "5"--- |
| Convert to boolean | bool()_____bool(1) → True--- |
| Add numbers | +_____2+3 → 5--- |
| Subtract numbers | -_____5-2 → 3--- |
| Multiply numbers | _____2*3 → 6--- |
| Divide numbers | /_____5/2 → 2.5--- |
| Integer division | //_____5//2 → 2--- |
| Modulo (remainder) | %_____5%2 → 1--- |
| Power operation | _____2**3 → 8--- |
| Equal comparison | ==_____5==5 → True--- |
| Not equal comparison | !=_____5!=3 → True--- |
| Greater than comparison | >_____5>3 → True--- |
| Less than comparison | <_____2<3 → True--- |
| Greater or equal | >=_____5>=5 → True--- |
| Less or equal | <=_____3<=5 → True--- |
| Logical AND | and_____True and False → False--- |
| Logical OR | or_____True or False → True--- |
| Logical NOT | not_____not True → False--- |
| Increment variable | +=_____x=1→x+=1→2--- |
| Conditional statement | if_____if 1<2--- |
| For loop | for_____for i in[1]--- |
| While loop | while_____while x<1--- |
| Break loop | break_____break--- |
| Continue loop | continue_____continue--- |
| Create list | list_____[1,2,3]--- |
| Create tuple | tuple_____(1,2)--- |
| Create set | set_____{1,2}--- |
| Create dictionary | dict_____{"a":1}--- |
| Access element | []_____[1,2][0] → 1--- |
| Get length | len()_____len([1,2]) → 2--- |
| Define function | def_____def f():--- |
| Return value | return_____return x--- def sumar(a, b): return a + b resultado = sumar(2, 3) print(resultado) |
| Append element | append()_____[1].append(2)--- |
| Insert element | insert()_____[1].insert(0,9)--- |
| Extend list | extend()_____[1].extend([2])--- |
| Remove last item | pop()_____[1,2].pop()→2--- |
| Count occurrences | count()_____[1,1].count(1)→2--- |
| Find index | index()_____[1,2].index(2)→1--- |
| Sort list | sort()_____[2,1].sort()--- |
| Sorted copy | sorted()_____sorted([2,1])→[1,2]--- |
| Uppercase string | upper()_____"a".upper()→"A"--- |
| Lowercase string | lower()_____"A".lower()→"a"--- |
| Remove spaces | strip()_____" a ".strip()→"a"--- |
| Replace text | replace()_____"a".replace("a","b")--- |
| Split string | split()_____"a,b".split(",")--- |
| Generate range | range()_____list(range(3))--- |
| Zip iterables | zip()_____list(zip([1],[2]))--- |
| Try block | try_____try--- |
| Catch exception | except_____except--- |
| Finally block | finally_____finally--- |
| Raise exception | raise_____raise Error--- |
| Sum values | sum()_____sum([1,2])→3--- |
| Minimum value | min()_____min([1,2])→1--- |
| Maximum value | max()_____max([1,2])→2--- |
| Absolute value | abs()_____abs(-5)→5--- |
| Round number | round()_____round(3.6)→4--- |
| Get type | type()_____type(5)→int--- |
| Check all true | all()_____all([1,True])→True--- |
| Check any true | any()_____any([0,1])→True--- |
| List comprehension | list comprehension_____[x for x in[1]]--- |
| Lambda function | lambda_____(lambda x:x+1)(1)→2--- x = 10 suma = lambda x : x + 3 print(suma(x)) |
| Map function | map()_____list(map(abs,[-1]))--- palabras = ["hola", "mundo"] resultado = map(str.upper, palabras) print(list(resultado)) |
| Shuffle list, mezclar los elementos de una lista al azar | mezclar los elementos de una lista al azar shuffle()_____random.shuffle([1,2]) import random lista = [1,2,3,4] random.shuffle(lista) print(lista) |
| Exit program | sys_____sys.exit()---, import sys |