Python Pages

Dot Net Perls has example pages for many languages, with explanations and code side by side (for easy understanding).


Use a list to store elements. Append to, remove from and loop over lists.Python List Examples


Apply the not-operator to see if an expression is False. Invert the value of booleans.Python not: If Not True

2D list.

Create a list of lists, or a 2D list. Append empty lists to a list and add elements.Python 2D List Examples


Use the array type to improve memory efficiency of numerical data.Python Array Examples: Integer Performance


Review built-in functions in the Python language. These are used in many programs.Python Built In Functions


Use the bytes, bytearray and memoryview types. Represent data in an efficient way.Python bytes, bytearray Examples (memoryview)


Use the class keyword. Call the init method to initialize a class.Python Class Examples: Init and Self


Use the console window. Get input from the user and write with print statements.Python Console Programs: Input and Print


Perform conversions on objects. Convert tuples, strings, lists and dictionaries.Python Convert Types


Use the datetime module. Parses date strings and perform other useful tasks.Python Datetime Methods: Date, Timedelta


Use the dictionary: operate on dictionaries and test performance in programs.Python Dictionary Examples


Handle errors: use the try, except and raise keywords. Use finally to always run code.Python Error: Try, Except and Raise


Handle text files and use pickle. Read in the lines of a text file.Python File Handling (with open, write)

Find, index.

Use the find, index and count methods. Search strings in loops for substrings.Python Find String: index and count


Iterate over the characters in a string with for. Use enumerate, reversed and range.Python for: Loop Over String Characters


Use the if, elif and else-statements. Write expressions and nested ifs.Python If Examples: Elif, Else


Use lambda expressions. Pass a lambda expressions to another method.Python Lambda Expressions


Use the len method on strings. Len returns the length of a string, dictionary, list, set or tuple.Python Len (String Length)

Lower, upper.

Use the lower, upper, islower and isupper methods. Call title and capitalize.Python Lower and Upper: Capitalize String


Use the map built-in function. Map applies a lambda to each element.Python Map Examples (Use Lambda on Each Element)


Use math methods. Review methods like sqrt, math.floor and math.ceil.Python Math Examples


Use the random module and the randint method. Call random.choice on a list.Python Random Numbers: randint, random.choice


Use the re.sub and re.subn methods to invoke a method for matching strings.Python Re Sub, Subn Methods

Regular expressions.

Use regular expressions and the re module. Call match, search, split and findall.Python Re Match, Search Examples

Remove duplicates.

Use a set to remove duplicate elements from a list without changing the order of elements.Python Remove Duplicates From List


Call round to round numbers up and down. With math.ceil a number is rounded up.Python Round Up and Down (Math Round)


Use sets, set syntax and set methods. A set is similar to a dictionary but has no values.Python Set Examples


Use the slice syntax on lists and strings. A slice has a start, stop and step.Python Slice Examples: Start, Stop and Step


Sort elements: sort a list, a dictionary and use the sorted method with keys.Python Sort Examples: Sorted List, Dictionary


Call the split method to separate strings. Use rsplit, splitlines and partition.Python Split String Examples

String slice.

Use slices on strings to take substrings. Slice syntax works as a substring method.Python Substring Examples


See a list of methods that can be used on strings. Review string literal syntax.Python String


Use the strip, lstrip and rstrip methods. Handle whitespace and other characters.Python Strip Examples


Use tuples to store separate values together. Pack, unpack and benchmark tuples.Python Tuple Examples


Understand the while-loop. While continues until a terminating condition is met.Python while Loop Examples
Dot Net Perls
© 2007-2019 Sam Allen. All rights reserved. Written by Sam Allen,