Here are some code samples in Python that you might find useful.
Basic Python Script
Below is a simple Python script that prints "Hello, World!" to the console.
print("Hello, World!")
List Comprehension
List comprehension is a concise way to create lists in Python. Here's an example of creating a list of squares from a list of numbers.
numbers = [1, 2, 3, 4, 5]
squares = [x**2 for x in numbers]
print(squares)
Function Definition
Functions allow you to encapsulate code that can be reused. Here's a function that calculates the factorial of a number.
def factorial(n):
if n == 0:
return 1
return n * factorial(n - 1)
print(factorial(5))
For more advanced Python tutorials, check out our Python Basics.
Python