Python Program to Limit the number of records returned from a query

To limit the number of records returned from a MySQL query using Python, you can use the `LIMIT` keyword in your SQL statement. Here's an example program :
Program :
import mysql.connector

# Establishing connection to the database
mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  password="yourpassword",
  database="yourdatabase"
)

# Creating a cursor object
mycursor = mydb.cursor()

# SQL statement to select the first 10 records from the table
sql = "SELECT * FROM yourtable LIMIT 10"

# Executing the SQL command
mycursor.execute(sql)

# Fetching the results
results = mycursor.fetchall()

# Displaying the results
for row in results:
  print(row)

# Closing the database connection
mydb.close()
Note : Replace `yourusername`, `yourpassword`, `yourdatabase`, and `yourtable` with your own values.

This program selects the first 10 records from the `yourtable` table and displays them. You can change the number 10 to any other value to limit the number of records returned.