Sequences and Conversions Examples
Learn to generate Fibonacci numbers, use recursion, and convert decimals to binary, octal, and hex. Master sequence logic and numeric transformations that frequently appear in practice questions.
Python Program to Find ASCII Value of Character
Uses ord().
print(ord('A'))
Output
65
Python Program to Print the Fibonacci sequence
Generates Fibonacci numbers.
n = 10
a, b = 0, 1
out = []
for _ in range(n):
out.append(a)
a, b = b, a + b
print(out)
Output
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Converts base representations.
n = 255 print(bin(n)) print(oct(n)) print(hex(n))
Output
0b11111111 0o377 0xff
Python Program to Display Fibonacci Sequence Using Recursion
Uses recursive function.
def fib(n):
return n if n < 2 else fib(n-1) + fib(n-2)
print([fib(i) for i in range(10)])
Output
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Python Program to Find Sum of Natural Numbers Using Recursion
Recursive sum.
def sumN(n):
return n if n <= 1 else n + sumN(n-1)
print(sumN(10))
Output
55
Python Program to Find Factorial of Number Using Recursion
Recursive factorial.
def fact(n):
return 1 if n <= 1 else n * fact(n-1)
print(fact(5))
Output
120
Python Program to Convert Decimal to Binary Using Recursion
Recursive conversion.
def tobin(n):
return '0' if n == 0 else (tobin(n//2).lstrip('0') + str(n%2))
print(tobin(10))
Output
1010
Keep Practicing
Use the online Python compiler to run examples and test variations. Reinforce learning by building small scripts for each topic.
FAQ
Learn Python by Practicing Examples
Hands-on practice is the fastest way to understand Python. Each example focuses on a single concept—from variables, strings, lists, and dictionaries to loops, functions, classes, exceptions, and file I/O. Modify examples, add new functions, and see how clean design leads to readable, maintainable code.
Use our tools to deepen learning: the Python Compiler to run snippets, and the Python Tutorial for structured lessons.
Beginner-Friendly
Start with variables, operators, and control flow. Build confidence with small, readable programs.
Practical Patterns
Practice lists, dicts, comprehensions, functions, classes, exceptions, and file handling.
Grow Skills
Explore generators and decorators to write expressive, reusable code.