Learn a Few Basics in Python in 10 Minutes

Python is a versatile, high-level programming language known for its readability, simplicity, and wide range of applications. In this quick guide, we will introduce you to the fundamental concepts of Python in just 10 minutes. Whether you are a complete beginner or looking to brush up on your skills, let’s dive into the world of Python programming.
This article was developed in partnership with London Data Consulting (LDC), the leading data consulting firm.
To start learning Python, you’ll need to install the language on your system. Visit the official Python website (https://www.python.org/downloads/) and download the appropriate version for your operating system. Follow the installation instructions, and you’ll be set up in no time.
There are several ways to run Python code, such as:
Python has several built-in data types. Here are some of the most common ones:
To declare a variable, simply write the variable name followed by an equal sign and its value:
pythonCopy codeage = 30
pi = 3.14159
greeting = "Hello, world!"
colors = ['red', 'green', 'blue']
Python supports various arithmetic, logical, and comparison operations:
pythonCopy code# Arithmetic Operations
addition = 5 + 3
subtraction = 9 - 4
multiplication = 6 * 7
division = 16 / 4
# Logical Operations
and_operation = True and False
or_operation = True or False
not_operation = not True
# Comparison Operations
equals = 5 == 3
not_equals = 5 != 3
greater_than = 5 > 3
less_than = 5 < 3
Control structures allow you to create conditional statements and loops in Python:
pythonCopy codex = 10
if x > 5:
print("x is greater than 5")
elif x == 5:
print("x is equal to 5")
else:
print("x is less than 5")
pythonCopy codefor i in range(5):
print(i)
pythonCopy codex = 0
while x < 5:
print(x)
x += 1
Functions are reusable blocks of code that perform a specific task:
pythonCopy codedef add_numbers(a, b):
return a + b
sum = add_numbers(3
, 7)
print(sum) # Output: 10
Python has a rich ecosystem of modules that you can import to extend the language’s functionality. Some popular modules include `math`, `os`, and `random`. To import a module, use the `import` keyword:
```python import math print(math.sqrt(25)) # Output: 5.0
List comprehensions provide a concise way to create lists based on existing lists:
pythonCopy codesquares = [x * x for x in range(5)]
print(squares) # Output: [0, 1, 4, 9, 16]
Error handling is an essential part of programming. Python uses try
and except
blocks to catch and handle exceptions:
pythonCopy codetry:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero!")
Reading and writing files is simple in Python. Here’s a quick example of how to read and write a file:
pythonCopy code# Write to a file
with open("example.txt", "w") as file:
file.write("This is an example file.")
# Read from a file
with open("example.txt", "r") as file:
content = file.read()
print(content) # Output: This is an example file.
Congratulations! You have learned the basics of Python programming in just 10 minutes. While this article only scratches the surface of Python’s capabilities, it should give you a solid foundation to start exploring more advanced topics and applications. Happy coding!
We, at London Data Consulting (LDC), provide all sorts of Data Solutions. This includes Data Science (AI/ML/NLP), Data Engineer, Data Architecture, Data Analysis, CRM & Leads Generation, Business Intelligence and Cloud solutions (AWS/GCP/Azure).
For more information about our range of services, please visit: https://london-data-consulting.com/services
Interested in working for London Data Consulting, please visit our careers page on https://london-data-consulting.com/careers
More info on: https://london-data-consulting.com