Tagged: python
Everything tagged "python", newest first.
Python Coding Exercise #62: Substrings, Parts 1 and 2
Two beginner Python exercises on slicing in a loop — print all the substrings of a word that start with its first character, then all the substrings that end with its last character, using for loops and while loops.
Python Coding Exercise #61: A Framed Word
A beginner Python exercise on string methods and string multiplication — print a word in the centre of a 30-character frame of asterisks, using center() and a manual version with len() and floor division.
Built-in Functions in Python: A Beginner's Guide
A beginner-friendly guide to Python's built-in functions — what each one does, how to read its result, and where it is used in real programs, with simple examples for input and output, type conversion, numbers, collections, objects and running code.
String Methods in Python: A Beginner's Guide
A beginner-friendly guide to Python's string methods — what each one does, with simple examples for changing case, trimming, aligning, searching, replacing, splitting, joining, checking and formatting text.
Python Coding Exercise #60: Right-Aligned
A beginner Python exercise on string methods — print a string so that exactly 20 characters are shown, filling the start with asterisks, using rjust() and a manual version with len() and string multiplication.
Python Coding Exercise #59: Underlining
A beginner Python exercise on loops, len() and string multiplication — keep asking for strings, print each one underlined with dashes of the same length, and stop when the user presses Enter on an empty line.
Python Coding Exercise #58: A Line and a Rectangle of Hashes
Two beginner Python exercises on repeating output — print a line of hash characters of a chosen width, then repeat that line to draw a rectangle, with a for loop and a while loop compared.
Python Coding Exercise #57: Second and Second to Last Characters
A beginner Python exercise on string indexes and short-circuit conditions — compare the second and second to last characters of a string, and learn why a very short string needs a length check first.
Python Coding Exercise #56: End to Beginning
A beginner Python exercise on string indexing and while loops — print a string in reverse, one character per line, by counting an index down from -1 using negative indexes.
Python Coding Exercise #55: The Longer String
A beginner Python exercise on len() and if, elif and else — compare the lengths of two strings and print whichever is longer, or a message when they are equally long.