https://docs.python.org/3/reference/lexical_analysis.html
Learning Python
viernes, 30 de enero de 2026
martes, 23 de diciembre de 2025
function parameters
# 1️⃣ *args — Extra positional parameters
def print_numbers(*args):
print("Positional numbers:", args)
print_numbers(1, 2, 3, 4)
# Output:
# Positional numbers: (1, 2, 3, 4)
print()
# 2️⃣ **kwargs — Extra keyword parameters
def print_info(**kwargs):
print("Keyword info:", kwargs)
print_info(name="Alice", age=17, country="FR")
# Output:
# Keyword info: {'name': 'Alice', 'age': 17, 'country': 'FR'}
print()
# 3️⃣ * — Force keyword-only arguments
def connect(host, port, *, timeout=5, ssl=False):
print(host, port, timeout, ssl)
connect("localhost", 5432, timeout=10, ssl=True)
# Output:
# localhost 5432 10 True
print()
# 4️⃣ ** in a call — Unpack dict into keywords
def greet(name, age):
print(f"Hello {name}, you are {age} years old!")
data = {"name": "Bob", "age": 20}
greet(**data)
# Output:
# Hello Bob, you are 20 years old!
print()
# 5️⃣ Combined example with all of them
def full_example(a, b, *args, c=10, **kwargs):
print("a, b:", a, b)
print("args:", args)
print("c:", c)
print("kwargs:", kwargs)
full_example(1, 2, 3, 4, 5, c=99, x=100, y=200)
# Output:
# a, b: 1 2
# args: (3, 4, 5)
# c: 99
# kwargs: {'x': 100, 'y': 200}
martes, 27 de mayo de 2025
iterating
>>> i=0
>>> while i<len(a.keys()):
... print(a[list(a.keys())[i]])
... i=i+1
...
Ambiorix
43
195
domingo, 6 de abril de 2025
Pyhon Exception
try:
result = 10 / a
except Exception as e:
print(f"An unexpected error occurred: {e}")
else:
print("Codigo funciona")
finally:
print("Siempre corre")
domingo, 16 de marzo de 2025
python generators
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
def test(i):
n=0
while n<i:
if n==3:
yield 'We reached the limit'
else:
yield n
n=n+1
m=test(24)
print(next(m))
print(next(m))
print(next(m))
print(next(m))
///////
0
1
2
We reached the limit
jueves, 13 de febrero de 2025
while and if
i=0
m=True
while m:
print(i)
i+=1
if i==10:
m=False
0
1
2
3
4
5
6
7
8
9
find missing number from a list range
l1=[1,2,5,6]
l2=[7, 1, 3, 5, 6]
def find_missing_number(l1):
max_n=max(l1)+1
min_n=min(l1)
c=[a for a in range(min_n,max_n) ]
missing_n=[a for a in c if a not in l1]
return missing_n
print(find_missing_number(l1))
print(find_missing_number(l2))
[3, 4]
[2, 4]