Strings 00 - Introduction Flashcards

Review Major Concepts of the Strings Basics in the Python Programming Language

1
Q

Answer: What is a variable?

A

Think of variables as labels that you can assign to values. You can also say that a variable references a certain value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Answer: What is a String?

A

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”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Answer: What is a Method?

A

A method is an action that Python can perform on a piece of data, like a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Answer: What are Some Methods for Strings?
Hint: there are 47 methods for strings.

A

Capitalize: stringName.capitalize()
Case Fold: stringName.casefold()
Center: stringName.center()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Answer: What is an F-String

A

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()}!”)
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe the ‘center’ method for a string data type.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly