Programming Flashcards
What does “.lower ()” do in Python?
.lower() - Prints the quote in all lower case letters.
What does “.upper ()” do in Python?
.upper() - Prints the quote in all upper case letters.
What does “.title ()” do in Python?
.title() - Prints the first letter of each word as a capital letter.
What does “.capitalize ()” do in Python?
.capitalize() - It prints the quote; the first letter of the sentence with a capital letter.
What does “.strip ()” do in Python?
.strip() - It prints the quote; the first letter of the sentence with a capital letter.
What does “.replace (“excellent”, “outstanding”)” in Python?
.replace(“excellent”, “outstanding”) - It prints the quote but replaces “excellent” with “outstanding”.
What does “.centre (500)” do in Python?
.centre(500) - It prints the quote in the centre.
Strings as arrays (lists):
Each character in a string has an index (position).
Slicing strings:
You can also create substrings (part of a full string) or split your strings where needed. This is called slicing.
Converting characters:
All characters can be represented by a decimal(whole) number using ASCII or UNICODE.
We can use string manipulation to convert characters to code and code back to a character.
e.g.
Convert number to character.
print (chr (97))
e.g.
Convert character to number.
print (ord( “b”))
Comparison operator:
A == B
Equivalence (e.g. If x=5 or if x==5)
Comparison operator:
A != B
Does not equal (e.g. if x!=5)
Comparison operator:
A < B
Less than (e.g. if x<5)
Comparison operator:
A <= B
Less than or equal to (e.g. if x<=5)
Comparison operator:
A > B
Greater than (e.g. if x>5)