Python Basics Flashcards

1
Q

After you create a string, can it be changed? Why?

A

No, because it is immutable.

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

Immutable

A

Impossible to modify

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

Why are there options to use either a double or single quote to make a string?

A

So that if the string contains either of those two characters, you wont unintentionally close the string early.

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

What is an escape sequence?

A

a character that tells the interpreter to read a character a certain way that may normally be reserved for specific syntax.

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

What are examples of escape sequences?

A

\n is new line

“”” tripple quotes also let you use both single and double quotes in a string

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

What is concatination?

A

use +, it will add two strings together. Remember to use proper spacing, if you dont include a space in a string, it wont show up.

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

What is in place addition?

A

+= It will append a string into a string already stored in a variable.

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

What function will tell you the length of a string?

A

len(var_name)

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

Everything that you create in python is an _____.

A

Object

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

What is a method?

A

An ability of an object. Or, functions that belong to an object.

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

How do you access methods that an object owns?

A

By using dot notation. E.g, there is a method called upper that converts all characters in a string to upper case, so you can say:

var_name.upper()

and the output will be all caps version of a string you called var_name

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

What is string formatting?

A

Allows you to create a re-usable template that can be filled with data. You include a set of curly braces (called a placeholder) in a string where you want to be able to insert data, then when you call the format function, you pass data in the parens in the order that they appear in the original string.

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

How do you find out if a string contains a part of a string?

A

in e.g. “pop” in “popcorn” returns True

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

What is a boolean value?

A

True or false

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

how do you cooerce a data type into becoming a boolean value?

A

bool()

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

how do you neggate a boolean value? (return its opposite)

A

use the not keyword

17
Q

How does the “and” keyword work?

A

and will result into True only if both the operands are True

18
Q

How does the “or” keyword work?

A

or will result into True if any of the operands is True

19
Q

What is conditional branching?

A

Running specific blocks of code based on their value.

20
Q

What is the comparison operator?

A

== , it returns true or false

21
Q

What is the best practice for indentation in Python?

A

4 spaces.

22
Q

What is elif?

A

Branching keyword, combo of else if. Allows you to add an additional branch to an if else statement.

23
Q

How do you check to see if something does NOT equal something else?

A

!=