string format methods - Introduction to Python: Absolute Beginner Module 1 Video 21

Veröffentlicht am: 27 Juli 2021
auf dem Kanal: Book Simplifiers
106
6

Concept: String Format Methods
Using string formatting methods
the following methods can be applied to string objects
.capitalize() - capitalizes the first character of a string
.lower() - all characters of a string are made lowercase
.upper() - all characters of a string are made uppercase
.swapcase() - all characters of a string are made to switch case upper becomes lower and vice versa
.title() - each 'word' separated by a space is capitalized
Example
String Formatting Methods
print("ms. Browning is in her office.".capitalize())
fav_color = "green"
print(fav_color.capitalize(), fav_color, fav_color,"and", fav_color.upper()+"!")
Task 1: multi-part
[ ] format with .capitalize(), .lower(), .upper(), .swapcase()
Note: use print()

[ ] get input for a variable, fav_food, that describes a favorite food

[ ] display fav_food as ALL CAPS, used in a sentence


[ ] display fav_food as all lower case, used in a sentence


[] display fav_food with swapped case, used in a sentence


[] display fav_food with capitalization, used in a sentence




fav_color = "Forest Green"
[] display the fav_color variable as upper, lower, swapcase, and capitalize formatting in a single print() statement


Auf dieser Seite können Sie das Online-Video string format methods - Introduction to Python: Absolute Beginner Module 1 Video 21 mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Book Simplifiers 27 Juli 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 106 Mal angesehen und es wurde von 6 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!