Python Syntax Flashcards

1
Q

What symbol tells Python to interpret the following as a comment?

A

#

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

What function tells a computer to talk?

A

print()

The message should be surrounded by “ “ or ‘ ‘
Be consistent with whichever chosen

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

What are the printed words as a result of the print() function referred to as?

A

Output

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

What are blocks of text called?

A

Strings

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

Does it matter which kind of quotation is used for a string?

A

No, either “” or ‘’

Just be consistent with whichever chosen.

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

How do you assign variables?

A

By using the equal sign (=)

message_string = “Hello there”
# Prints “Hello there”
print(message_string)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can variables start with numbers?

A

No, but they can have numbers after the first letter.

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

Can variables have spaces or symbols other than an underscore ( _ )?

A

No

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

What does Python refer to mistakes as?

A

Errors.

It will point to the location where an error occurred with a ^ character.

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

What are two common errors encountered while writing Python?

A

SyntaxError

NameError

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

What does SyntaxError mean?

A

There is something wrong with the way your program is written
- punctuation that does not belong, a command where it is not expected, or a missing parentheses can all trigger SyntaxError.

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

When does a NameError occur?

A

When the Python interpreter sees a word it does not recognize.

Code that contains something that looks like a variable but was never defined will throw a NameError.

Or when the quotes are never used but should have been.

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

What does a SyntaxError: EOL mean?

A

A string wasn’t closed, or wasn’t closed with the same quote-character that started it.

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

What is the modulo operator?

A

A companion to division.

It is indicated by % and returns the remainder after division is performed.

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

What is a float?

A

A number with a decimal point.
You can define a float with numbers after the decimal point or by just including a decimal point at the end.

You can also define a float using scientific notation, with e indicating the power of 10.

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

How do you write a string that spans multiple lines?

A

Use triple quotes
“””136 Whowho Rd
Apt 7
Whosville”””

This can also be used for long comments if you don’t assign it as a variable.

17
Q

What is a Boolean?

A

A variable that is either true or false.

A value of true corresponds to an integer value of 1.

A value of false corresponds to a value of 0.

18
Q

How would you convert an integer to a string?

A

str()
Example:
age = 13
print “I am” + str(age) + “years old!”

For a reversal, we use int()

int_addition = int(number1) + int(number 2)

19
Q

How do you deal with apostrophes in strings?

A

Put a backlash \ before the apostrophe.

“There\’s a snake in my boots!”