Chapter 2: Variables and Simple Data Types Flashcards

(33 cards)

1
Q

Example of creating a variable in python

A

message = “Hello Python Crash Course reader”

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

Ayhting inside ____ is considered a _____ in python

A

quotes, string

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

‘This is a string’
is this a string in python?

A

yes

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

name = “ada lovelace”
print(name.title())

A

Ada Lovelace

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

Other string case methods

A

.upper()
.lower()

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

first_name = “ada”
last_name = “lovelace”
full_name = f”{first_name} {last_name}”
print(full_name)

A

ada lovelace
These strings are called f-strings

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

full_name = “{} {}”.format(first_name, last_name)

A

f strings are only in python 3.6, so this is the method you would have to use if using earlier versions. version

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

In python, you can also add white space to strings with ____ ro ____

A

\t, \n

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

.rstrip()

A

removes whitespace from the right side

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

.lstrip()

A

removes whitespace from the left hand side

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

message = ‘One of Python’s strengths is its diverse community.’
print(message)

A

File “apostrophe.py”, line 1
message = ‘One of Python’s strengths is its diverse community.’
^
SyntaxError: invalid syntax

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

Python uses ____ multiplication symbols to represent exponents

A

two

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

> > 3**2

A

9

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

When dividing any two numbers, even if they are integers that result in a whol number, you will always get a ______

A

float

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

> > > universe_age = 14_000_000_000
print(universe_age)

A

14000000000

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

x,y,z = 0,0,0

A

multiple assignment

17
Q

When you want to treat a variable as a constant in your code, make the
name of the variable all _____ letters.

A

capital
MAX_CONNECTIONS = 5000

18
Q

How to make a string from another data type

A

str()
»> str(98.6)
‘98.6’

19
Q

How to combine string variables

20
Q

How to duplicate a string

A

> > > start = ‘Na ‘ * 4 + ‘\n’

21
Q

How to get an individual character in string

A

[]
»> letters = ‘abcdefghijklmnopqrstuvwxyz’
»> letters[0]
‘a’

22
Q

How to get a substring

A

using a slice

23
Q

[:]

A

extracts the entire sequence from start to end.

24
Q

[ start :]

A

specifies from the start offset to the end.

25
[: end ]
specifies from the beginning to the end offset minus 1.
26
[ start : end ]
indicates from the start offset to the end offset minus 1.
27
[ start : end : step ]
extracts from the start offset to the end offset minus 1, skipping characters by step.
28
How to get length
len()
29
.split() tasks = 'get gloves,get mask,give cat vitamins,call ambulance' >>> tasks.split(',')
'get gloves', 'get mask', 'give cat vitamins', 'call ambulance']
30
.replace() >>> setup = "a duck goes into a bar..." >>> setup.replace('duck', 'marmoset') '
a marmoset goes into a bar...'
31
.strip() world = " earth " >>> world.strip()
'earth'
32
f'The {thing.capitalize()} is in the {place.rjust(20)}'
'The Wereduck is in the werepond'
32
>>> thing = 'wereduck' >>> place = 'werepond' >>> f'The {thing} is in the {place}'
'The wereduck is in the werepond'