Chapter 4 Flashcards
What is an integer ( data type )?
Whole numbers both positive and negative
What is a float ( real number ) ?
Real numbers, decimals and intergers. All Integers can be floats but not the other way.
What is a string ( data type )?
Multiple characters ( a list of characters )
What is the difference between a strongly-typed and a weakly-typed language? And provide examples.
In a strongly typed language (C, C++) you have to explicitly specify the data type in a variable.
In a weakly typed language (python), the programming language “guesses” the data type.
len(string)
len(“orange”) => 6
string.capitalize()
“orange”.capitalize() => Orange
string.lower()
“BAnAna”.lower() => banana
string.upper()
“BAnANa”.upper() => BANANA
string.rjust(number)
“Dog”.rjust(50) => (50 length)Dog
string.replace(oldvalue, newvalue)
“Dog”.replace(“o”, “i”) => Dig
string.split(separator)
“myname”.split(“y”) => [“my”, “name]
string.strip(characters)
“…##..banana..#..”.strip(.#) => banana
string.join(list)
“+”.join([“Bill”,”Barney”,”Ben”]) => Bill + Barney + Ben
string.find(substring)
“The missing word”.find(miss) => 4
string.format (items)
“My name is {name} and I am {age} years old”.format(name=“Bob”,age= “27”) => My name is Bob and I am 27 years old.