Python Pages

Dot Net Perls has example pages for many languages, with explanations and code side by side (for easy understanding).
List. Use a list to store elements. Append to, remove from and loop over lists.Python List Examples
Not. 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
Array. Use the array type to improve memory efficiency of numerical data.Python Array Examples: Integer Performance
Built-ins. Review built-in functions in the Python language. These are used in many programs.Python Built In Functions
Byte. Use the bytes, bytearray and memoryview types. Represent data in an efficient way.Python bytes, bytearray Examples (memoryview)
Class. Use the class keyword. Call the init method to initialize a class.Python Class Examples: Init and Self
Console. Use the console window. Get input from the user and write with print statements.Python Console Programs: Input and Print
Convert. Perform conversions on objects. Convert tuples, strings, lists and dictionaries.Python Convert Types
Datetime. Use the datetime module. Parses date strings and perform other useful tasks.Python Datetime Methods: Date, Timedelta
Dictionary. Use the dictionary: operate on dictionaries and test performance in programs.Python Dictionary Examples
Error. Handle errors: use the try, except and raise keywords. Use finally to always run code.Python Error: Try, Except and Raise
Files. 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
For. Iterate over the characters in a string with for. Use enumerate, reversed and range.Python for: Loop Over String Characters
If. Use the if, elif and else-statements. Write expressions and nested ifs.Python If Examples: Elif, Else
Lambda. Use lambda expressions. Pass a lambda expressions to another method.Python Lambda Expressions
Len. 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
Map. Use the map built-in function. Map applies a lambda to each element.Python Map Examples (Use Lambda on Each Element)
Math. Use math methods. Review methods like sqrt, math.floor and math.ceil.Python Math Examples
Random. Use the random module and the randint method. Call random.choice on a list.Python Random Numbers: randint, random.choice
Re.sub. 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
Round. Call round to round numbers up and down. With math.ceil a number is rounded up.Python Round Up and Down (Math Round)
Set. Use sets, set syntax and set methods. A set is similar to a dictionary but has no values.Python Set Examples
Slice. Use the slice syntax on lists and strings. A slice has a start, stop and step.Python Slice Examples: Start, Stop and Step
Sort. Sort elements: sort a list, a dictionary and use the sorted method with keys.Python Sort Examples: Sorted List, Dictionary
Split. 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
String. See a list of methods that can be used on strings. Review string literal syntax.Python String
Strip. Use the strip, lstrip and rstrip methods. Handle whitespace and other characters.Python Strip Examples
Tuple. Use tuples to store separate values together. Pack, unpack and benchmark tuples.Python Tuple Examples
While. Understand the while-loop. While continues until a terminating condition is met.Python while Loop Examples
© 2007-2019 Sam Allen. Every person is special and unique. Send bug reports to
Dot Net Perls