Strings 00 - Introduction Flashcards
Review Major Concepts of the Strings Basics in the Python Programming Language
Answer: What is a variable?
Think of variables as labels that you can assign to values. You can also say that a variable references a certain value.
Answer: What is a String?
A string is a one type of data that contains a series of characters. Anything inside quotes is considered a string in Python, and you can use single or double quotes around your strings.
Example:
‘Example of a Single Quoted String’
“Example of a Double Quoted String”
Answer: What is a Method?
A method is an action that Python can perform on a piece of data, like a string.
Answer: What are Some Methods for Strings?
Hint: there are 47 methods for strings.
Capitalize: stringName.capitalize()
Case Fold: stringName.casefold()
Center: stringName.center()
Answer: What is an F-String
The f is for format, because Python formats the string by replacing the name of any variable in braces with its value.
Example:
~~~
full_name = f”{first_name} {last_name}”
print(f”Hello, {full_name.title()}!”)
~~~
Describe the ‘center’ method for a string data type.
Center Method
Description:
. Takes the original string and adds padding to both ends.
. The original string is included in the amount of padding specified.
. The center method take two arguments.
. First argument: Specifies the amount of padding; take a numeric value
. Second argument: The character used for padding; defaults to a space (“ “) when no second argument is provided.
Syntax: stringName.center(80, “x”)
Parameter Names / Argument Types: example
. width / number: 80
. fillchar / character: “x”
Returning Value: a string
Example Code:
stringName = “PYTHON”
stringName.center(80, “x”)
Output:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxPYTHONxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx