Chapter 2: Variables and data types Flashcards
create a variable and print the message that assigns a function to capitalize the first letter of each word
name = ‘ada lovelace’
print(name.title())
define: method in python
an action that python can perform on a piece of data
print a variable as all uppercase and all lowercase
name = ‘ada lovelace’
print(name.upper())
print(name.lower())
print a variable but only the first letter of the string should be uppercase
name = ‘ada lovelace’
print(name.capitalize())
print a first name and last name as separate variables, then combine them to make a complete name. also, make sure the first letters are capitalized
first_name = ‘ada’
last_name = ‘lovelace’
full_name = f”{first_name} {last_name}”
print(full_name.title())
what is the f in f”{first_name} {last_name}”, and what does it do?
the f means format. python uses the f to format the strings by replacing the variable name in the braces with the variable’s value
print out a string using the f-string, make sure the name is capitalized
print(f”Hello, {full_name.title()}”)
assign a f-string to a variable and print that variable out
message = f”Hello, {full_name.title()}”
print(message)
use the format method to create what is essentially this full_name = f”{first_name} {last_name}”
full_name = “{} {}”.format(first_name, last_name)
what is whitespace?
any nonprinting character, such as spaces, tabs, or end-of-line-symbols
add a tab to a string you want to print
print(“\tpython”)
add new lines to a string that has multiple items
print(“languages:\nPython\nC++\nJS”)
combine tabs and newlines
print(“languages:\n\tPython\n\tC++\n\tJS”)
print a variable that has extra whitespace on the right side and get rid of it
program = ‘python ‘
print(program.rstrip())
permanently delete white space by adding rstrip() to the variable
program = 'python ' program = program.rstrip()