Data Types And String Manipulation Flashcards

1
Q

What is a data type?

A

A classification that tells the computer what kind of data is being used and how it should be stored and processed.

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

What are the main data types in Python?

A

• Integer (int): Whole numbers (e.g., 5, -10)
• Float: Decimal numbers (e.g., 3.14, -0.01)
• String (str): Text enclosed in quotes (e.g., “hello”)
• Boolean (bool): True or False

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

What is a string in Python?

A

A sequence of characters enclosed in quotation marks (e.g., “Computer”).

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

How can you access characters in a string in Python?

A

Using indexing: string[index], where indexing starts at 0.

For example, “hello”[1] returns “e”.

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

How do you get the length of a string in Python?

A

Use the len() function — e.g., len(“hello”) returns 5.

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

How do you slice a string in Python?

A

Using string[start:end], which returns characters from the start index up to but not including the end index.

Example: “hello”[1:4] returns “ell”.

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

What does string.upper() do in Python?

A

Converts all letters in the string to uppercase.

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

What does string.lower() do in Python?

A

Converts all letters in the string to lowercase.

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

What does string.strip() do in Python?

A

Removes whitespace (or other characters) from the beginning and end of the string.

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

What does string.replace(old, new) do in Python?

A

Replaces all instances of the old substring with new.

Example: “hello”.replace(“l”, “x”) → “hexxo”.

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

What does string.find(sub) do in Python?

A

Returns the index of the first occurrence of the substring sub. If not found, it returns -1.

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

How do you concatenate (join) strings in Python?

A

Use the + operator.

Example: “Hello “ + “World” → “Hello World”.

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

How do you convert a string to an integer in Python?

A

Use int(string).

For example: int(“5”) → 5.

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

How do you convert an integer to a string in Python?

A

Use str(integer).

For example: str(10) → “10”.

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

What is string iteration in Python?

A

Using a loop to go through each character in a string, e.g.:
for letter in “hello”:
print(letter)

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

Why is it important to understand string manipulation in programming?

A

Because strings are used frequently in input/output, data processing, and communication with.