Variables Flashcards

1
Q

What is an example of a variable?

A

x = 5
y = “jhon”
print (x)
print (y)

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

what is another example of a variable?

A

x = 5
y = 6
z = x + y
print (z)

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

How are variables sensitive?

A

They are case sensitive.

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

What must a variable start with?

A

a letter or an underscore character

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

how do you create a multi variable?

A

x, y, z = (“Orange”, “Banana”, “Cherry”)
print(x)
print(y)
print(z)

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

how do you assign the same value to one variable?

A

x = y = z = (“Orange”)
print(x)
print(y)
print(z)

output = orange
orange
orange

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

How do you unpack a collection?

A

fruits = [“apple”, “banana”, “cherry”]
x, y, z, = fruits
print (x)
print (y)
print (z)

output = apple
banana
cherry

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

How do you output a variable?

A

x = “Print me”
print (x)

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

How do you output multiple variables?

A

With a comma
x = 5
y = “John”
print(x, y)

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

What are variables that are created outside of a function?

A

Global variables

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

What is an example of a global function?

A

x = “awesome”
def myfunc():
print(“Python is “ + x)
myfunc()

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

What happens when you create a variable with the same name inside a function?

A

Creates a local variable

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

What is an example of creating a local variable?

A

x = “awesome”

def myfunc():
x = “fantastic”
print(“Python is “ + x)

myfunc()

print(“Python is “ + x)

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

How do you create a global variable within a function?

A

def myfunc():
global x
x = “fantastic”

myfunc()

print(“Python is “ + x)

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

How do you CHANGE a global variable inside a function?

A

x = “awesome”

def myfunc():
global x
x = “fantastic”

myfunc()

print(“Python is “ + x)

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