Python for Kids
Blogs, articles, free Python projects and more for kids and teens learning to code with Python.
Dec 5 2023
Learn about the rich variety of control structures in Python and when to use each of them!
Read moreDec 3 2023
Here is some math + coding for you to convert days to years!
Read moreDec 2 2023
Learn about the Birthday Paradox with a simple calculator to understand its implications!
Read moreNov 30 2023
Here is some math + coding for you to convert minutes to days!
Read moreNov 23 2023
Here is some math + coding for you to convert seconds to years!
Read moreOct 24 2023
Here is some math + coding for you to convert days to seconds!
Read moreSep 26 2023
assertEqual() is a useful way to test your Python programs and double-check that they are working as intended.
Read moreSep 10 2023
Learn how to find if a given number is prime, using both math, and in Python!
Read moreAug 31 2023
Learn how to pretty print complex JSON data objects in Python!
Read moreAug 31 2023
Learn how to bold (and unbold) characters in your Python print statements!
Read moreJul 24 2023
How do you check if a Python object is iterable, i.e., can be iterated over? Learn three different ways.
Read moreJul 24 2023
How do you traverse a list in reverse order?
Read moreJul 23 2023
Learn how to pass a boolean command line argument to your Python program.
Read moreJul 23 2023
Learn how to pass command line arguments to your Python program, in particular a list of arguments!
Read moreJul 22 2023
How do you take a Python list and place its elements into a list interspersed with commas? Learn three different ways!
Read moreJul 22 2023
Learn three handy ways to obtain a list of all the alphabetic characters in Python!
Read moreJul 18 2023
You know about Python strings but do you know what a Python string buffer is?
Read moreJul 18 2023
Sometimes you will need to truncate a string in Python. Learn why and how!
Read moreJul 17 2023
Need a way to get rid of nuisance punctuation characters from a Python string? Learn three different ways!
Read moreJul 17 2023
Learn four different ways to remove newline characters from a Python string!
Read moreJun 21 2023
Do you know how to print line breaks in Python? Learn the different ways!
Read moreJun 21 2023
Every once in a while you will encounter a need to skip a line of code in your Python program under certain conditions. Learn how to do so!
Read moreJun 3 2023
You know about functions but do you know about functors in Python? Sounds funky!
Read moreMay 22 2023
Did you know there are six ways to multiply in Python? How? - you ask. Let us show you the ways...
Read moreMay 22 2023
Learn three quick ways to compute the average of a list in Python.
Read moreMay 20 2023
Here are handy ways to convert a Python list to a tuple!
Read moreMay 19 2023
Want to return multiple values from your Python function and need to understand how?
Read moreMay 12 2023
Learn three ways to conclude a Python program, from the most natural to the most serious!
Read moreMay 12 2023
Learn three different ways to add time delays in your Python program.
Read moreMay 9 2023
Learn what environment variables are in Python and how to set or change them!
Read moreMay 9 2023
Learn what environment variables are in Python and how to access them!
Read moreMay 9 2023
Learn two handy ways to find the parent directory in Python!
Read moreMay 8 2023
Learn a useful Python numpy function to create identity matrices.
Read moreMay 8 2023
Learn a convenient Python numpy function to extract diagonals from arrays!
Read moreMay 7 2023
numpy.any() is a handy function to test if any element in a given input Python numpy array evaluates to a True.
Read moreMay 7 2023
numpy.isnan() is a quick way to check if a given value is not a number (NaN).
Read moreMay 6 2023
Learn how you can find the gradient of a function denoted by values in an array!
Read moreMay 6 2023
Learn a handy way to split a numpy array into subarrays of possibly different sizes.
Read moreMay 5 2023
Learn how to add days to a given date in Python to arrive at a new date!
Read moreMay 5 2023
Haven’t you wondered what day of the week your future birthday will fall on? There is a method for that in Python!
Read moreMay 2 2023
numpy.cumsum() is a handy function used to compute cumulative sums. Learn how to use it!
Read moreMay 2 2023
numpy.repeat() is a very useful function that can be used to repeat elements in an array.
Read moreApr 29 2023
Learn to use numpy.roll() to rotate your array’s values circularly!
Read moreApr 29 2023
Use numpy.clip() to truncate values outside an interval in a given array.
Read moreApr 2 2023
Learn how to compare dates in Python using built-in functions and libraries!
Read moreMar 29 2023
Learn how to convert a Python boolean to a string value!
Read moreMar 29 2023
Learn how to convert a Python string to a boolean value!
Read moreMar 28 2023
Learn how to pad a Python string so it looks just the way you want it!
Read moreMar 28 2023
Learn three handy ways to remove the first character from a Python string!
Read moreMar 27 2023
When you wish to take a sneak peek at your Pandas dataframe, e.g., print only the first 10 records, there are handy ways to do that!
Read moreMar 27 2023
Sometimes your Pandas dataframe contains the columns you need but in the wrong order. Learn how to reorder columns in a dataframe!
Read moreMar 21 2023
Learn how to prepare useful summary tables using Pandas crosstab()!
Read moreMar 21 2023
Learn three handy ways to obtain a list of all the column names in a Pandas frame!
Read moreMar 14 2023
date_range() is a very useful function in Pandas that returns a set of evenly spaced dates in a given interval!
Read moreMar 14 2023
Learn a handy way to extract the nth row of a Pandas dataframe!
Read moreMar 13 2023
Learn how to construct tuple comprehensions in Python and what they are used for!
Read moreMar 13 2023
Learn how the hash() function works in Python, its uses, and applications!
Read moreMar 12 2023
The 'group' feature of Python regular expressions allows you to extract parts of matching strings and use them in your program.
Read moreMar 12 2023
A useful skill to know is to split a string into multiple elements based on (some) delimiter characters. Python’s re.split() function is what you need!
Read moreMar 12 2023
Want to create user-friendly tuples in your Python program? Use the namedtuple data structure from the Python collections module.
Read moreMar 12 2023
Tuples are incredibly useful data structures for your Python program. Learn how to unpack tuples in your program!
Read moreMar 2 2023
Use the Python math library to write your own rotating and scaling functions for vectors in Python!
Read moreMar 2 2023
Are you looking for a way to easily create evenly spaced numbers between two given values? If so, Python’s numpy.linspace() is just what you need!
Read moreMar 1 2023
What does it mean to slice a dictionary in Python?
Read moreMar 1 2023
How do you go about comparing two Python dictionaries?
Read moreFeb 28 2023
What does it mean to shuffle a Python dictionary? Are there easy ways to shuffle?
Read moreFeb 28 2023
Learn useful methods to serialize a Python dictionary into JSON format!
Read moreFeb 27 2023
Learn how to compute logarithms in regular base 10 using Python!
Read moreFeb 27 2023
Learn a handy way to compute the least common multiple of integer arguments in Python!
Read moreFeb 25 2023
In how many ways can you choose two candies from 4 candies? There is a Python math function for that!
Read moreFeb 25 2023
Sometimes you will have a dictionary mapping keys to values and you wish to unpack these entries into individual variable=value assignments. There is an elegant approach in Python to accomplish this task.
Read moreFeb 24 2023
Sometimes you will have a list of variables and you would like to create a dictionary with the variable names as keys and variable values as the mapped values. Here is a very simple way to do this!
Read moreFeb 24 2023
Here are three handy ways to check if a specified key exists in a Python dictionary!
Read moreFeb 23 2023
Learn what the cross product of two vectors is and how to find it in Python using numpy.cross()!
Read moreFeb 23 2023
How can you systematically find all the factors of a given number so that you don’t miss any factors? Here is a Python program to do just that!
Read moreFeb 22 2023
Are you a math geek and looking to access Euler’s number (the transcendental number “e”) in your Python program? The Python math library has the constant for you!
Read moreFeb 22 2023
Are you a physics geek and looking to access the Boltzmann constant in your Python program? There is a very easy way!
Read moreFeb 21 2023
You will come across a need to concatenate a string to an integer in your Python journey. Learn how to do so!
Read moreFeb 21 2023
In a Python loop what if you would like to know how many times you have been looping so far? There is a Python-ic way to do that!
Read moreFeb 20 2023
numpy.sum() is a handy function that returns the sum of elements of numpy arrays either all at once or along specified axes.
Read moreFeb 20 2023
A negative index into a string might seem counterintuitive but it has a very simple interpretation.
Read moreFeb 19 2023
Learn how to effectively end a function in Python!
Read moreFeb 19 2023
Python’s math.trunc() function is one of the easiest methods to grasp - it simply cuts out the decimal portion of its argument without rounding up or down.
Read moreFeb 18 2023
Learn how to find and return unique values from your numpy array!
Read moreFeb 18 2023
You might sometimes come across a Python list with None values. Learn how to remove these values!
Read moreFeb 16 2023
Learn how to split a list into sublists with predefined lengths!
Read moreFeb 16 2023
Lets write a simple Python program to find all the square numbers from 1 to 100!
Read moreFeb 15 2023
Want to print a list in Python without the annoying brackets and commas? Learn how to do so!
Read moreFeb 15 2023
numpy.round() is a handy function to round elements of your array. Learn how to use it!
Read moreFeb 11 2023
Learn two handy ways to remove the last character from a string in Python!
Read moreFeb 11 2023
Learn how to get access to pi, the irrational number, in your Python programs using the numpy library.
Read moreJan 31 2023
Learn three different ways to increment a value in a Python dictionary!
Read moreJan 31 2023
Become a Python dictionary expert by learning how to find the first key in a given dictionary!
Read moreJan 23 2023
Learn how to convert a string to a float in Python using just one function call!
Read moreJan 23 2023
How do you find all permutations of characters in a given string? This is one of those examples where recursion proves to be an ideal way to approach the problem.
Read moreJan 19 2023
A lambda is an unnamed, anonymous function in Python. A nested lambda is a lambda within a lambda. Learn when you might need it!
Read moreJan 17 2023
Learn the intricacies involved in converting a regular python list to a numpy array and what your options are!
Read moreJan 17 2023
Sometimes you will want to make an element-wise comparison of two numpy arrays. There is a function for that!
Read moreJan 14 2023
Python’s numpy.histogramdd() is a very useful function to compute histograms out of multidimensional data. Learn the different ways to use it!
Read moreJan 14 2023
Python numpy has a handy function to create an array of specified shape and type, filled with ones. Check it out!
Read moreJan 9 2023
Want to find the distance by foot between two locations in Python? Learn how to compute the Manhattan distance!
Read moreJan 9 2023
Want to find the shortest distance between two cities in Python? The numpy module has many options for you!
Read moreJan 8 2023
Lambda functions are 'use and throw' functions. Learn if you can split a lambda function across multiple lines and what the rules for writing lambda functions are!
Read moreJan 8 2023
Sometimes you just want to create your own custom maximum function; Python lambdas have a solution for you!
Read moreJan 7 2023
In your Python journey you will encounter a need to convert a Python range into a list. Learn three ways to do so!
Read moreJan 7 2023
Ranges are a staple of iteration in Python. Learn how to reverse a range!
Read moreJan 5 2023
Learn how to convert a comma-separated string into a list in Python, a very common operation!
Read moreJan 5 2023
Learn how to distribute candy evenly by computing the greatest common divisor!
Read moreDec 29 2022
A CamelCase string is one like Kodeclik or KodeclikOnlineAcademy, but not kodeclikonlineacademy. How can you check if a Python string is in CamelCase format?
Read moreDec 20 2022
Applying a function to each element of a list is such a handy and useful capability that you should learn all the ways Python makes it easy to do so!
Read moreDec 20 2022
In your Python journey, you will come across scenarios where you will need to check if a Python string is empty. Learn three ways to accomplish this frequent task.
Read moreDec 2 2022
Ever wondered how Python internally represents a string as bytes? There are handy functions to explore that!
Read moreNov 29 2022
The os.path.join() function in Python is a clean way to concatenate different strings to construct a complete filepath. Learn why and how to use it!
Read moreNov 29 2022
Python modules help logically organize code into multiple files; learn how to import a class from another file!
Read moreNov 27 2022
Learn how to programmatically move between directories in Python!
Read moreNov 27 2022
Learn how to programmatically delete a file from within Python!
Read moreNov 23 2022
Ever wanted to explore your directory but from within Python? Learn how!
Read moreNov 22 2022
Nested classes are those that are defined inside other classes. Learn when you will need this feature and how they are useful in object oriented programming!
Read moreNov 22 2022
In processing lists in Python you might find a need to skip values in the list. Learn four different ways to do so!
Read moreNov 18 2022
What if you have a list of tuples and desire to sort it in your own way? Learn two popular methods to do so!
Read moreNov 18 2022
Nested lists are useful data structures that are basically lists comprised of other lists. Learn when and how to use them in Python!
Read moreNov 14 2022
Learn how to unzip a list of tuples in Python, from the easiest to the most Pythonic way!
Read moreNov 14 2022
Learn six different ways to do element-by-element subtraction of two lists in Python!
Read moreNov 13 2022
Ever wanted to create directories programmatically from within Python? It is so easy!
Read moreNov 13 2022
The vars() function in Python inspects an object and returns a dictionary identifying the changeable attributes of the object along with their current values.
Read moreNov 12 2022
The next() function in Python retrieves the next item from an iterator (constructed over a data structure such as a list or dictionary). Learn how to use it!
Read moreNov 12 2022
Looking for a Python-ic way to swap positions of values in a Python dictionary? It just takes a few lines of code!
Read moreNov 11 2022
As your journey into Python goes forward you will come to a point where you wonder if Python is case sensitive. Read on!
Read moreNov 11 2022
The Python range function behaves in an off-by-one manner in how it does not include the end value. Learn how to create an inclusive range function!
Read moreNov 8 2022
Sometimes you will need a loop in Python that counts down rather than counts up. Learn how to reverse a range in Python!
Read moreNov 8 2022
Python’s divmod() is a very handy function that returns both the quotient and remainder of a division in a single step!
Read moreNov 7 2022
Learn to compute the tangent trigonometric ratio in Python with the Math.tan() function.
Read moreNov 7 2022
Learn to compute the cosine trigonometric ratio in Python with the Math.cos() function.
Read moreOct 17 2022
Learn to compute the sine trigonometric ratio in Python with the Math.sin() function.
Read moreOct 17 2022
Learn to solve 'math domain errors' in Python, one of the most common but sometimes frustrating error messages!
Read moreOct 8 2022
Learn about the math.isclose() function in Python and how to use it!
Read moreOct 8 2022
Learn how to factorize a number into its prime factors in Python, in two different ways!
Read moreOct 4 2022
Pascal’s triangle is a very useful construct in discrete math and can be easily computed in Python. Learn how!
Read moreOct 4 2022
Did you know you can retrieve the '-1'th element of a Python list? What? What does that mean?
Read moreJul 3 2022
A histogram is a plot of the counts of (grouped) items in a given dataset. Learn how to compute histograms in Python!
Read moreJul 3 2022
Have a Python dictionary and would like to loop through it? Here are four ways to do so!
Read moreMay 21 2022
Given two or more files how do you merge them into a single file? Learn to write a Python program to do just that!
Read moreMay 21 2022
A stack is a last-in-first-out (LIFO) data structure. Learn the many ways to create a stack in Python.
Read moreMay 21 2022
A queue is a first-in-first-out (FIFO) data structure. Learn the many ways to create a queue in Python.
Read moreMay 19 2022
Python loops are so expressive that you can do two things at once: count and iterate!
Read moreMay 19 2022
Have a Python string and need to remove parentheses from it? Learn three ways to do so!
Read moreMay 19 2022
Have two or more lists and need to iterate through them simultaneously? Here are the ways.
Read moreMay 18 2022
Looking for a quick way to compare two dictionaries in Python? Learn how!
Read moreMay 18 2022
Can you write an interactive Python program to take inputs from the user till the Enter key is pressed? Learn how!
Read moreMay 10 2022
Python’s range() function is very handy to write loops because it returns a list of numbers within a specified span of values.
Read moreMay 10 2022
Python’s sum function takes an iterable and returns the sum of elements in it. Learn how to use it!
Read moreMay 9 2022
Learn about four different ways to split a text file in Python into lines. Which one is your favorite?
Read moreMay 9 2022
Have a Python set and want to convert it into a tuple? Learn three ways to do so!
Read moreMay 4 2022
Have a Python string denoting a decimal and need to remove trailing zeros? Learn how!
Read moreMay 4 2022
Have a Python string denoting a number and need to remove leading zeros? Learn how!
Read moreApr 3 2022
Stacks are one of the most useful data structures in Python. Learn how to use them!
Read moreApr 3 2022
How should you name your Python files, functions, classes, modules, and packages? Read on to learn how!
Read moreFeb 20 2022
Can you have a Python program where a method has different meanings at different points in a program? Yes!
Read moreFeb 20 2022
Do you get the dreaded “Tuple Index Out of Range” error in your Python program? Learn what it means and how to fix it!
Read moreFeb 20 2022
Would you like to time your Python program to see how fast it runs? Learn about ways to measure elapsed time!
Read moreFeb 20 2022
An ordered set is just like a set in that it disallows duplicates but it maintains the order of elements. Learn how to implement ordered sets in Python!
Read moreFeb 18 2022
Have a Python set and want to pop an element? Here’s how to do it!
Read moreFeb 18 2022
You will sometimes encounter the need to measure the size of files from within a Python program. Here are 5 ways to do so!
Read moreFeb 18 2022
Learn how to print any object into a string using Python’s custom methods!
Read moreFeb 17 2022
It is sometimes handy to take an object and convert it into a string. Learn Python’s very useful str() function!
Read moreFeb 17 2022
Have a string and need to check if it actually denotes an integer? Here are 4 ways to do so!
Read moreFeb 15 2022
If you dabble in Python lists, here are useful ways to prepend elements to a list!
Read moreFeb 15 2022
Do you know the difference between 5/2 and 5//2 in Python? When do you use which operator?
Read moreFeb 13 2022
Learn how to write boolean expressions using Python’s in built boolean operators!
Read moreFeb 13 2022
Private methods in a Python class are a good way to encapsulate functionality. Learn when you can make use of them!
Read moreFeb 9 2022
Python has versatile ways to format strings, i.e., to create strings from templates. Learn how they work!
Read moreFeb 9 2022
Need to send hundreds of emails and looking for a convenient solution? Learn how to use a mail API and Python to programmatically send emails!
Read moreFeb 8 2022
Learn about Python’s special method __call__ which makes objects callable, leading to more readable code!
Read moreFeb 8 2022
Python is one of the most multifaceted languages out there; learn about 5 different ways to print a list! Which one is your favorite?
Read moreFeb 7 2022
hasattr() is a very useful function in Python that can be used to check if a given object has a specified attribute.
Read moreFeb 7 2022
'not in' as the name indicates is an operator that checks if a given input is not present in a given sequence. See where we can make use of it!
Read moreJan 31 2022
What is the remainder when 7 to the power of 49 is divided by 5? Python’s pow() is a handy function to get you the result in one line!
Read moreJan 31 2022
Ever wonder how Python stores characters internally? Learn about the Python chr() function!
Read moreJan 30 2022
Analogous to max(), the min() function in Python takes an iterable (e.g., a list) as input and returns the minimum value in that iterable.
Read moreJan 30 2022
The max() function in Python is a versatile function that takes any type of iterable (e.g., a list) as input and returns the maximum value in that iterable.
Read moreDec 30 2021
Learn about 8 different ways to initialize a Python dictionary. Which one is your favorite?
Read moreDec 30 2021
Learn how to work with empty dictionaries in Python: creating them and testing for emptiness.
Read moreDec 30 2021
Dictionaries hold key-value pairs in a data structure and it is often useful to find the length of a dictionary. Learn how!
Read moreDec 30 2021
If...else statements are important to any Python programmer; the inline if is a shorthand that leads to more readable statements.
Read moreDec 30 2021
Memory errors can occasionally happen in your Python program. Learn four reasons why they happen and how to to fix them.
Read moreDec 30 2021
stderr, or 'standard error', is the channel where error messages from your Python program are recorded. Learn how to print to stderr from your program.
Read moreDec 30 2021
Haven’t you found it necessary to sometimes take a string and capitalize the first letter of each word? Here are 5 handy ways to do so.
Read moreDec 30 2021
The XOR operator in Python computes the logical exclusive disjunction of two boolean variables or two binary numbers.
Read moreDec 28 2021
Python’s if not operator tests if some condition is not true and can be a succinct way to describe some types of program logic.
Read moreDec 28 2021
Learn about the many ways to copy a list in Python and which one to use in a given setting.
Read moreDec 28 2021
Python startswith() is a very handy method to check if a string starts with a certain prefix.
Read moreDec 28 2021
Python strings sometimes are made up of numbers and can thus be interpreted in a numerical manner. isnumeric() is a very useful method for Python programmers.
Read moreDec 27 2021
How do you find the length of a list in Python? Learn about Python’s built-in len() method and other functions.
Read moreDec 27 2021
Ternary operators in Python are nice syntactic shorthands for conditional statements that make your program more readable. Read on to understand how and when to use them.
Read moreDec 27 2021
Checkout this handy tutorial to create empty lists in Python or check if a given list is empty.
Read moreDec 27 2021
Python has very useful functions that make it easy to write to text files and even append to existing files. See how!
Read moreDec 14 2021
It is easy to use Python to read content from a file and process them in your program. Read on to see how!
Read moreOct 26 2021
Concatenating strings refers to joining them one after the other. Python provides multiple ways to concatenate strings.
Read moreOct 25 2021
Pointers are very common in low-level languages like C and C++ and although you do not need to use them explicitly in Python, understanding how they work behind the scenes will make you appreciate many implementation details.
Read moreOct 19 2021
Python’s reduce() function takes a function and uses it to perform a rolling computation over an iterable such as a list.
Read moreOct 19 2021
Python’s map() function can be viewed as a shorthand for a for loop. It takes a function and an iterable (e.g., a list or array) and applies the same function on each element of the iterable.
Read moreOct 17 2021
Discover Python sets! Python provides a very flexible set data structure and a wide range of operations so you don’t have to implement your own.
Read moreSep 27 2021
Fibonacci numbers are a famous sequence of numbers that occur in many natural contexts. Learn how to generate and experiment with them using Python programs.
Read moreSep 27 2021
A loop is a basic building block of coding and is referred to as a programming structure. Let’s take a look at the types of loops and how they are used within a program.
Read moreSep 13 2021
Python’s Turtle is a popular module that provides many useful functions for drawing graphics, animations, and games. Learn how you can command the turtle to draw graphics!
Read moreAug 2 2021
Learn why Python is one of the most popular programming languages out there and the myriad places where it is used.
Read moreJuly 19 2021
Python’s sqrt() computes square roots and you can use it in interesting ways to solve mathematical problems.
Read moreJuly 18 2021
Python’s print() is a versatile function that provides various options to format and style the output from your programs.
Read moreJuly 17 2021
Recursion is a style of programming where a function calls itself one or more times repeatedly until a desired condition is met. Many classical algorithms in computer science are recursive in nature.
Read moreJuly 15 2021
Magic squares add up to the same number along rows, columns, and diagonals. Here is a Python program to generate them.
Read moreJuly 14 2021
Learn to use the Pygame library in Python to create your first game. This tutorial is meant for beginners looking to get started with Pygame.
Read moreJuly 13 2021
Learn about the Python pygame library and its capabilities.
Read moreJuly 10 2021
Arrays and Lists are two very similar data structures in Python but have important differences. Read on to learn about them!
Read moreJuly 9 2021
Learn about this ancient mathematical puzzle and the classical computer science solution to it, along with a Python implementation.
Read moreJuly 8 2021
Learn to write your own Python program that will generate a random password.
Read moreJuly 6 2021
Algorithms are pervasive in computer science - read this post to learn about five of the most popular algorithms and their myriad applications.
Read moreJuly 5 2021
Quicksort is a very popular in-place sorting algorithm so named because it is significantly faster than many other sorting algorithms. Learn about it including an implementation in Python.
Read moreJuly 3 2021
Merge sort is a classical divide-and-conquer algorithm. Learn the details of how merge sort works and a sample implementation in Python.
Read moreJuly 2 2021
Insertion sort is a very simple algorithm for sorting, mimicking the way you sort cards in your hand. Get into the details of how Insertion Sort works and a sample implementation in Python.
Read moreJune 29 2021
Bubble Sort is a very popular and simple algorithm for sorting. Learn how Bubble Sort works and how to implement it using Python.
Read moreJune 28 2021
Python’s enumerate() function is used to loop through strings, list, arrays and any other iterable object. Use iterators to build a search engine!
Read moreJune 25 2021
What is an algorithm? How do they surface in our everyday lives? Learn about the history of algorithms, the types of algorithms, and some famous algorithms in computer science.
Read moreJune 23 2021
Random numbers are crucial to realism in gaming, cryptography, and simulation. Learn all about random numbers, how they are used, and how to generate them in Python.
Read moreDec 10 2019