Day: May 29, 2021

Learn Python By Example – Add Padding Around String

Try, Except, and Finally Create data /* Create some data */ scores = [23,453,54,235,74,234] Try something that doesn’t work /* Try to: */ try: /* Add a list of integers and a string */ scores + ‘A string of characters.’ /* If you get an error, set the error as ‘e’, */ except Exception as …

Learn Python By Example – Swapping Variable Values

Swapping Variable Values Setup the originally variables and their values one = 1 two = 2 View the original variables ‘one =’, one, ‘two =’, two (‘one =’, 1, ‘two =’, 2) Swap the values one, two = two, one View the swapped values, notice how the values for each variable have changed ‘one =’, …

learn Python By Example – String Operations

String Operations Python 3 has three string types str() is for unicode bytes() is for binary data bytesarray() mutable variable of bytes   Create some simulated text. string = ‘The quick brown fox jumped over the lazy brown bear.’ Capitalize the first letter. string_capitalized = string.capitalize() string_capitalized ‘The quick brown fox jumped over the lazy …